-
Notifications
You must be signed in to change notification settings - Fork 7
/
kube_create_secret_test.go
62 lines (56 loc) · 1.63 KB
/
kube_create_secret_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
package svc_test
import (
"context"
"fmt"
"reflect"
"runtime"
"strings"
"testing"
"time"
"github.com/nerdalize/nerd/svc"
)
func TestCreateSecret(t *testing.T) {
for _, c := range []struct {
Name string
Timeout time.Duration
Input *svc.CreateSecretInput
IsOutput func(tb testing.TB, out *svc.CreateSecretOutput)
IsErr func(error) bool
}{
{
Name: "when a zero value input is provided it should return a validation error",
Timeout: time.Second * 5,
Input: nil,
IsErr: svc.IsValidationErr,
IsOutput: func(t testing.TB, out *svc.CreateSecretOutput) {
assert(t, out == nil, "output should be nil")
},
},
{
Name: "when a valid input is provided it should return a secret with a unique name",
Timeout: time.Second * 5,
Input: &svc.CreateSecretInput{Image: "smoketest", Project: "nerdalize", Registry: "quay.io", Username: "test", Password: "test"},
IsErr: nil,
IsOutput: func(t testing.TB, out *svc.CreateSecretOutput) {
assert(t, out != nil, "output should not be nil")
assert(t, strings.Contains(out.Name, "s-"), "secret name should be generated and prefixed")
},
},
} {
t.Run(c.Name, func(t *testing.T) {
di, clean := testDI(t)
defer clean()
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, c.Timeout)
defer cancel()
kube := svc.NewKube(di)
out, err := kube.CreateSecret(ctx, c.Input)
if c.IsErr != nil {
assert(t, c.IsErr(err), fmt.Sprintf("unexpected '%#v' to match: %#v", err, runtime.FuncForPC(reflect.ValueOf(c.IsErr).Pointer()).Name()))
}
if c.IsOutput != nil {
c.IsOutput(t, out)
}
})
}
}