Skip to content

Commit

Permalink
Inlined test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrossley3 committed Apr 29, 2020
1 parent ed4b8f9 commit 697db26
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions pkg/reconciler/knativeserving/common/aggregated_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"sigs.k8s.io/yaml"
)

type ruleAggregationFixture struct {
Name string
Input *unstructured.Unstructured
Database *unstructured.Unstructured
OverwriteExpected bool
}

var ruleAggregationData = []byte(`
func TestAggregationRuleTransform(t *testing.T) {
tests := []struct {
Name string
Input *unstructured.Unstructured
Existing *unstructured.Unstructured
OverwriteExpected bool
}{}
var testData = []byte(`
- name: "existing role has rules"
input:
kind: ClusterRole
Expand All @@ -45,7 +45,7 @@ var ruleAggregationData = []byte(`
- matchLabels:
serving.knative.dev/controller: "true"
rules: []
database:
existing:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down Expand Up @@ -75,33 +75,28 @@ var ruleAggregationData = []byte(`
rules: []
overwriteExpected: false
`)

func TestAggregationRuleTransform(t *testing.T) {
tests := []ruleAggregationFixture{}
err := yaml.Unmarshal(ruleAggregationData, &tests)
err := yaml.Unmarshal(testData, &tests)
if err != nil {
t.Error(err)
return
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
runRuleAggregationTest(t, &test)
mock := mockGetter{test.Existing}
original := test.Input.DeepCopy()
transformer := AggregationRuleTransform(&mock)
if err := transformer(test.Input); err != nil {
t.Error(err)
}
if test.OverwriteExpected {
util.AssertDeepEqual(t, test.Input, test.Existing)
} else {
util.AssertDeepEqual(t, test.Input, original)
}
})
}
}

func runRuleAggregationTest(t *testing.T, test *ruleAggregationFixture) {
mock := mockGetter{test.Database}
original := test.Input.DeepCopy()
transformer := AggregationRuleTransform(&mock)
transformer(test.Input)
if test.OverwriteExpected {
util.AssertDeepEqual(t, test.Input, test.Database)
} else {
util.AssertDeepEqual(t, test.Input, original)
}
}

type mockGetter struct {
u *unstructured.Unstructured
}
Expand Down

0 comments on commit 697db26

Please sign in to comment.