forked from bzon/ecr-k8s-secret-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
55 lines (50 loc) · 1.19 KB
/
main_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
package main
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecr"
v1 "k8s.io/api/core/v1"
testclient "k8s.io/client-go/kubernetes/fake"
)
func TestCreateDockerCfg(t *testing.T) {
tt := []struct {
tokenOutput *ecr.GetAuthorizationTokenOutput
success bool
name string
}{
{
tokenOutput: &ecr.GetAuthorizationTokenOutput{
AuthorizationData: []*ecr.AuthorizationData{
&ecr.AuthorizationData{
ProxyEndpoint: aws.String("xxx"),
AuthorizationToken: aws.String("xxx"),
},
}},
success: true,
name: "with valid ecr token output",
},
{
tokenOutput: &ecr.GetAuthorizationTokenOutput{},
success: false,
name: "empty ecr token output",
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
_, err := createDockerCfg(tc.tokenOutput)
if err != nil {
if tc.success {
t.Fatal(err)
}
}
})
}
}
func TestApplyDockerCfgSecret(t *testing.T) {
kclient := &kubernetesAPI{client: testclient.NewSimpleClientset()}
err := kclient.applyDockerCfgSecret(
[]byte("test"), "docker-secret", "test-namespace", v1.SecretTypeOpaque)
if err != nil {
t.Fatal(err)
}
}