Skip to content

Commit

Permalink
pkg/git: AuthOptions.Validate() test improvements
Browse files Browse the repository at this point in the history
Adds more test cases for Validate() and an error for unknown transport.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz authored and hiddeco committed Oct 25, 2021
1 parent 1f962d3 commit ad9b382
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Oomb3gD/TRf/nAdVED+k81GdLzciYdUGtI71/qI47G0nMBluLRE=

keyRingFingerprintFixture = "3299AEB0E4085BAF"

malformedKeyRing = `
malformedKeyRingFixture = `
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQSuBF9+HgMRDADKT8UBcSzpTi4JXt/ohhVW3x81AGFPrQvs6MYrcnNJfIkPTJD8
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestCommit_Verify(t *testing.T) {
Encoded: []byte(encodedCommitFixture),
Signature: signatureCommitFixture,
},
keyRings: []string{malformedKeyRing},
keyRings: []string{malformedKeyRingFixture},
wantErr: "failed to read armored key ring: unexpected EOF",
},
{
Expand Down
2 changes: 2 additions & 0 deletions pkg/git/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (o AuthOptions) Validate() error {
}
case "":
return fmt.Errorf("no transport type set")
default:
return fmt.Errorf("unknown transport '%s'", o.Transport)
}
return nil
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/git/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func TestAuthOptions_Validate(t *testing.T) {
},
wantErr: "invalid 'http' auth option: 'password' requires 'username' to be set",
},
{
name: "Valid HTTP transport",
opts: AuthOptions{
Transport: HTTP,
Username: "example",
Password: "foo",
},
},
{
name: "HTTPS transport with password requires user",
opts: AuthOptions{
Expand All @@ -84,6 +92,20 @@ func TestAuthOptions_Validate(t *testing.T) {
},
wantErr: "invalid 'https' auth option: 'password' requires 'username' to be set",
},
{
name: "Valid HTTPS transport",
opts: AuthOptions{
Transport: HTTPS,
Username: "example",
Password: "foo",
},
},
{
name: "Valid HTTPS without any config",
opts: AuthOptions{
Transport: HTTPS,
},
},
{
name: "SSH transport requires identity",
opts: AuthOptions{
Expand Down Expand Up @@ -121,6 +143,27 @@ func TestAuthOptions_Validate(t *testing.T) {
opts: AuthOptions{},
wantErr: "no transport type set",
},
{
name: "Valid SSH transport",
opts: AuthOptions{
Transport: SSH,
Identity: []byte(privateKeyPassphraseFixture),
Password: "foobar",
KnownHosts: []byte(knownHostsFixture),
},
},
{
name: "No transport",
opts: AuthOptions{},
wantErr: "no transport type set",
},
{
name: "Unknown transport",
opts: AuthOptions{
Transport: "foo",
},
wantErr: "unknown transport 'foo'",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ad9b382

Please sign in to comment.