Skip to content

Commit ab2ba72

Browse files
Weeblinribbybibby
authored andcommitted
Implement simple generation of ClusterRoleses
1 parent 1d3fbe8 commit ab2ba72

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b // indirect
2222
github.com/kylelemons/godebug v1.1.0
2323
github.com/leodido/go-urn v1.2.0 // indirect
24+
github.com/maxatome/go-testdeep v1.9.2 // indirect
2425
github.com/pkg/errors v0.9.1
2526
github.com/pmylund/go-cache v2.1.0+incompatible
2627
github.com/sirupsen/logrus v1.7.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ github.com/mattn/go-sqlite3 v1.12.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
664664
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
665665
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
666666
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
667+
github.com/maxatome/go-testdeep v1.9.2 h1:5D7u/JkeG0A/HDTbZ/CFFmpYZPeWN+uGQ1IbsEHYlCo=
668+
github.com/maxatome/go-testdeep v1.9.2/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70=
667669
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
668670
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
669671
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=

pkg/permissions/generate_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package permissions
33
import (
44
"testing"
55

6-
"github.com/d4l3k/messagediff"
76
"github.com/jetstack/preflight/pkg/agent"
87
"github.com/jetstack/preflight/pkg/datagatherer/k8s"
8+
"github.com/maxatome/go-testdeep/td"
99
rbac "k8s.io/api/rbac/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -35,28 +35,24 @@ func TestGenerateRBAC(t *testing.T) {
3535
},
3636
},
3737
expectedClusterRoleBindings: []rbac.ClusterRoleBinding{
38-
3938
{
4039
TypeMeta: metav1.TypeMeta{
4140
Kind: "ClusterRoleBinding",
4241
APIVersion: "rbac.authorization.k8s.io/v1",
4342
},
44-
4543
ObjectMeta: metav1.ObjectMeta{
4644
Name: "jetstack-secure-agent-ClusterRole-reader",
4745
},
48-
4946
Subjects: []rbac.Subject{
5047
{
5148
Kind: "ServiceAccount",
5249
Name: "agent",
5350
Namespace: "jetstack-secure",
5451
},
5552
},
56-
5753
RoleRef: rbac.RoleRef{
5854
Kind: "ClusterRole",
59-
Name: "jetstack-secure-agent-secret-reader",
55+
Name: "jetstack-secure-agent-secrets-reader",
6056
APIGroup: "rbac.authorization.k8s.io",
6157
},
6258
},
@@ -68,9 +64,7 @@ func TestGenerateRBAC(t *testing.T) {
6864
for _, input := range testCases {
6965
got := GenerateRoles(input.dataGatherers)
7066
toBeTest := GenerateBindings(got)
71-
if diff, equal := messagediff.PrettyDiff(input.expectedClusterRoleBindings, toBeTest); !equal {
72-
t.Errorf("%s:\n%s", input.description, diff)
73-
t.Fatalf("unexpected difference in RBAC cluster role: \ngot \n%v\nwant\n%v", got, input.expectedClusterRoleBindings)
74-
}
67+
68+
td.Cmp(t, input.expectedClusterRoleBindings, toBeTest)
7569
}
7670
}

0 commit comments

Comments
 (0)