forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_test.go
55 lines (51 loc) · 1.62 KB
/
controller_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 config
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/fake"
)
func Test_parseConfigMap(t *testing.T) {
cc := controller{emptyConfigFunc: EmptyConfigFunc}
t.Run("Empty", func(t *testing.T) {
_, err := cc.parseConfigMap(&apiv1.ConfigMap{})
assert.NoError(t, err)
})
t.Run("Config", func(t *testing.T) {
c, err := cc.parseConfigMap(&apiv1.ConfigMap{Data: map[string]string{"config": "containerRuntimeExecutor: pns"}})
if assert.NoError(t, err) {
assert.Equal(t, "pns", c.(*Config).ContainerRuntimeExecutor)
}
})
t.Run("Complex", func(t *testing.T) {
c, err := cc.parseConfigMap(&apiv1.ConfigMap{Data: map[string]string{"containerRuntimeExecutor": "pns", "artifactRepository": ` archiveLogs: true
s3:
bucket: my-bucket
endpoint: minio:9000
insecure: true
accessKeySecret:
name: my-minio-cred
key: accesskey
secretKeySecret:
name: my-minio-cred
key: secretkey`}})
if assert.NoError(t, err) {
assert.Equal(t, "pns", c.(*Config).ContainerRuntimeExecutor)
assert.NotEmpty(t, c.(*Config).ArtifactRepository)
}
})
t.Run("IgnoreGarbage", func(t *testing.T) {
_, err := cc.parseConfigMap(&apiv1.ConfigMap{Data: map[string]string{"garbage": "garbage"}})
assert.NoError(t, err)
})
}
func Test_controller_Get(t *testing.T) {
kube := fake.NewSimpleClientset()
c := controller{configMap: "my-config-map", kubeclientset: kube, emptyConfigFunc: EmptyConfigFunc}
ctx := context.Background()
config, err := c.Get(ctx)
if assert.NoError(t, err) {
assert.Empty(t, config)
}
}