...
1
16
17 package create
18
19 import (
20 "testing"
21
22 corev1 "k8s.io/api/core/v1"
23 apiequality "k8s.io/apimachinery/pkg/api/equality"
24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 )
26
27 func TestCreateServiceAccount(t *testing.T) {
28 tests := map[string]struct {
29 options *ServiceAccountOpts
30 expected *corev1.ServiceAccount
31 }{
32 "service account": {
33 options: &ServiceAccountOpts{
34 Name: "my-service-account",
35 },
36 expected: &corev1.ServiceAccount{
37 TypeMeta: metav1.TypeMeta{
38 Kind: "ServiceAccount",
39 APIVersion: "v1",
40 },
41 ObjectMeta: metav1.ObjectMeta{
42 Name: "my-service-account",
43 },
44 },
45 },
46 }
47
48 for name, tc := range tests {
49 t.Run(name, func(t *testing.T) {
50 serviceAccount, err := tc.options.createServiceAccount()
51 if err != nil {
52 t.Errorf("unexpected error:\n%#v\n", err)
53 return
54 }
55 if !apiequality.Semantic.DeepEqual(serviceAccount, tc.expected) {
56 t.Errorf("expected:\n%#v\ngot:\n%#v", tc.expected, serviceAccount)
57 }
58 })
59 }
60 }
61
View as plain text