forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ca_configmap_test.go
60 lines (54 loc) · 1.27 KB
/
ca_configmap_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
package storage_test
import (
"testing"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"github.com/grafana/loki/operator/internal/handlers/internal/storage"
)
func TestIsValidConfigMap(t *testing.T) {
type test struct {
name string
cm *corev1.ConfigMap
wantHash string
wantErrorMsg string
}
table := []test{
{
name: "valid CA configmap",
cm: &corev1.ConfigMap{
Data: map[string]string{
"service-ca.crt": "has-some-data",
},
},
wantHash: "de6ae206d4920549d21c24ad9721e87a9b1ec7dc",
wantErrorMsg: "",
},
{
name: "missing `service-ca.crt` key",
cm: &corev1.ConfigMap{},
wantErrorMsg: "key not present or data empty: service-ca.crt",
},
{
name: "missing CA content",
cm: &corev1.ConfigMap{
Data: map[string]string{
"service-ca.crt": "",
},
},
wantErrorMsg: "key not present or data empty: service-ca.crt",
},
}
for _, tst := range table {
tst := tst
t.Run(tst.name, func(t *testing.T) {
t.Parallel()
hash, err := storage.CheckCAConfigMap(tst.cm, "service-ca.crt")
require.Equal(t, tst.wantHash, hash)
if tst.wantErrorMsg == "" {
require.NoError(t, err)
} else {
require.EqualError(t, err, tst.wantErrorMsg)
}
})
}
}