...
1
16
17 package bootstrap
18
19 import (
20 "testing"
21
22 v1 "k8s.io/api/core/v1"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/types"
25 "k8s.io/apimachinery/pkg/util/dump"
26 core "k8s.io/client-go/testing"
27 bootstrapapi "k8s.io/cluster-bootstrap/token/api"
28 "k8s.io/kubernetes/pkg/apis/core/helper"
29 )
30
31 func newTokenSecret(tokenID, tokenSecret string) *v1.Secret {
32 return &v1.Secret{
33 ObjectMeta: metav1.ObjectMeta{
34 Namespace: metav1.NamespaceSystem,
35 Name: bootstrapapi.BootstrapTokenSecretPrefix + tokenID,
36 ResourceVersion: "1",
37 UID: types.UID("uid" + tokenID),
38 },
39 Type: bootstrapapi.SecretTypeBootstrapToken,
40 Data: map[string][]byte{
41 bootstrapapi.BootstrapTokenIDKey: []byte(tokenID),
42 bootstrapapi.BootstrapTokenSecretKey: []byte(tokenSecret),
43 },
44 }
45 }
46
47 func addSecretExpiration(s *v1.Secret, expiration string) {
48 s.Data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expiration)
49 }
50
51 func addSecretSigningUsage(s *v1.Secret, value string) {
52 s.Data[bootstrapapi.BootstrapTokenUsageSigningKey] = []byte(value)
53 }
54
55 func verifyActions(t *testing.T, expected, actual []core.Action) {
56 for i, a := range actual {
57 if len(expected) < i+1 {
58 t.Errorf("%d unexpected actions: %s", len(actual)-len(expected), dump.Pretty(actual[i:]))
59 break
60 }
61
62 e := expected[i]
63 if !helper.Semantic.DeepEqual(e, a) {
64 t.Errorf("Expected\n\t%s\ngot\n\t%s", dump.Pretty(e), dump.Pretty(a))
65 continue
66 }
67 }
68
69 if len(expected) > len(actual) {
70 t.Errorf("%d additional expected actions", len(expected)-len(actual))
71 for _, a := range expected[len(actual):] {
72 t.Logf(" %s", dump.Pretty(a))
73 }
74 }
75 }
76
View as plain text