forked from lightninglabs/lndinit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s_test.go
78 lines (70 loc) · 1.73 KB
/
k8s_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 main
import (
"testing"
"encoding/base64"
"github.com/stretchr/testify/require"
)
var (
dummyString = []byte("This is a simple string")
dummyStringB64 = base64.StdEncoding.EncodeToString(dummyString)
dummyStringNewline = []byte("This is a simple string newline\n")
dummyStringNewlineB64 = base64.StdEncoding.EncodeToString(
dummyStringNewline,
)
)
// TestSecretToString makes sure that a raw secret can be turned into a string
// correctly.
func TestSecretToString(t *testing.T) {
testCases := []struct {
name string
input []byte
base64 bool
expectErr bool
result string
}{{
name: "plain string",
input: dummyString,
result: string(dummyString),
}, {
name: "plain base64",
input: []byte(dummyStringB64),
base64: true,
result: string(dummyString),
}, {
name: "invalid base64",
input: dummyString,
base64: true,
expectErr: true,
}, {
name: "plain base64 with newline in encoded",
input: []byte(dummyStringB64 + "\r\n"),
base64: true,
result: string(dummyString),
}, {
name: "string with newline",
input: dummyStringNewline,
result: string(dummyStringNewline),
}, {
name: "base64 with newline in original",
input: []byte(dummyStringNewlineB64),
base64: true,
result: string(dummyStringNewline),
}, {
name: "base64 with newline in encoded",
input: []byte(dummyStringNewlineB64 + "\r\n"),
base64: true,
result: string(dummyStringNewline),
}}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(tt *testing.T) {
result, err := secretToString(tc.input, tc.base64)
if tc.expectErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.result, result)
})
}
}