pkg/git: AuthOptions.Validate() test improvements
Adds more test cases for Validate() and an error for unknown transport. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
parent
4a23126c6a
commit
942c310195
|
@ -106,7 +106,7 @@ Oomb3gD/TRf/nAdVED+k81GdLzciYdUGtI71/qI47G0nMBluLRE=
|
|||
|
||||
keyRingFingerprintFixture = "3299AEB0E4085BAF"
|
||||
|
||||
malformedKeyRing = `
|
||||
malformedKeyRingFixture = `
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQSuBF9+HgMRDADKT8UBcSzpTi4JXt/ohhVW3x81AGFPrQvs6MYrcnNJfIkPTJD8
|
||||
|
@ -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",
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
@ -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{
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue