forked from d2iq-archive/mesos-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
78 lines (73 loc) · 2.3 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package httpcli_test
import (
"testing"
. "github.com/mesosphere/mesos-dns/httpcli"
"github.com/mesosphere/mesos-dns/httpcli/basic"
"github.com/mesosphere/mesos-dns/httpcli/iam"
)
func TestValidate(t *testing.T) {
basic.Register()
iam.Register()
defer RegistryReset()
for i, tc := range []struct {
am AuthMechanism
cm ConfigMap
expectingErr bool
expectedErr error
}{
{am: "", cm: nil}, // sanity check, auth-none should not require any configuration
{am: "123", cm: nil, expectingErr: true, expectedErr: ErrUnregisteredFactory},
{am: AuthIAM, cm: nil, expectingErr: true, expectedErr: ErrMissingConfiguration},
{am: AuthBasic, cm: nil, expectingErr: true, expectedErr: ErrMissingConfiguration},
{ // IAM expects configuration
am: AuthIAM,
cm: ConfigMapOptions{iam.Configuration(iam.Config{})}.ToConfigMap(),
expectingErr: true,
expectedErr: iam.ErrInvalidConfiguration,
},
{ // valid IAM configuration
am: AuthIAM,
cm: ConfigMapOptions{iam.Configuration(iam.Config{
ID: "foo",
PrivateKey: "bar",
LoginEndpoint: "blah",
})}.ToConfigMap(),
},
{ // Basic expects configuration
am: AuthBasic,
cm: ConfigMapOptions{basic.Configuration(basic.Credentials{})}.ToConfigMap(),
expectingErr: true,
expectedErr: basic.ErrInvalidConfiguration,
},
{ // valid Basic configuration
am: AuthBasic,
cm: ConfigMapOptions{basic.Configuration(basic.Credentials{
Principal: "foo",
Secret: "bar",
})}.ToConfigMap(),
},
{ // valid Basic configuration, principal only
am: AuthBasic,
cm: ConfigMapOptions{basic.Configuration(basic.Credentials{
Principal: "foo",
})}.ToConfigMap(),
},
{ // valid Basic configuration, secret only
am: AuthBasic,
cm: ConfigMapOptions{basic.Configuration(basic.Credentials{
Secret: "bar",
})}.ToConfigMap(),
},
} {
err := Validate(tc.am, tc.cm)
if tc.expectingErr && err == nil {
t.Errorf("test case %d expected error but got none", i)
}
if !tc.expectingErr && err != nil {
t.Errorf("test case %d unexpected error: %+v", i, err)
}
if tc.expectingErr && err != nil && tc.expectedErr != nil && tc.expectedErr != err {
t.Errorf("test case %d expected error %v but got %v instead", i, tc.expectedErr, err)
}
}
}