-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from opentofu/test_git_tag_parsing
- Loading branch information
Showing
4 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package github | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_parseTagsFromStdout(t *testing.T) { | ||
cases := map[string]struct { | ||
input []string | ||
expected []string | ||
expectedErr error | ||
}{ | ||
"Empty input": { | ||
input: []string{""}, | ||
expected: []string{}, | ||
}, | ||
// Successful | ||
"Simple Tag": { | ||
input: []string{"314159265358979 refs/tags/v0.0.1"}, | ||
expected: []string{"v0.0.1"}, | ||
}, | ||
"Multiple Tags": { | ||
input: []string{"314159265358979 refs/tags/v0.0.1", "314159265358979 refs/tags/v0.1.1", "314159265358979 refs/tags/v1.0.1"}, | ||
expected: []string{"v0.0.1", "v0.1.1", "v1.0.1"}, | ||
}, | ||
// Invalid entries (ignored) | ||
"No Tags": { | ||
input: []string{}, | ||
expected: []string{}, | ||
}, | ||
"Empty Tags": { | ||
input: []string{""}, | ||
expected: []string{}, | ||
}, | ||
"Multiple Tags w/ Invalid": { | ||
input: []string{"314159265358979 HEAD", "314159265358979 refs/tags/v0.1.1", "314159265358979 refs/tags/v1.0.1"}, | ||
expected: []string{"v0.1.1", "v1.0.1"}, | ||
}, | ||
// Error cases | ||
"Missing Field": { | ||
input: []string{"borkborkborkrefs/tags/"}, | ||
expectedErr: errors.New("invalid format for tag 'borkborkborkrefs/tags/', expected two fields"), | ||
}, | ||
"Extra Field": { | ||
input: []string{"bork bork refs/tags/"}, | ||
expectedErr: errors.New("invalid format for tag 'bork bork refs/tags/', expected two fields"), | ||
}, | ||
"Missing tags/refs": { | ||
input: []string{"314159265358979refs/tags/ v0.0.1"}, | ||
expectedErr: errors.New("invalid format for tag '314159265358979refs/tags/ v0.0.1', expected 'refs/tags/' prefix"), | ||
}, | ||
"Missing version": { | ||
input: []string{"314159265358979 refs/tags/"}, | ||
expectedErr: errors.New("invalid format for tag '314159265358979 refs/tags/', no version provided"), | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
out, err := parseTagsFromStdout(tc.input) | ||
|
||
assert.Equal(t, tc.expectedErr, err) | ||
assert.Equal(t, tc.expected, out) | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters