Skip to content

Commit 64e1f99

Browse files
author
Kate Osborn
committed
Panic when policy is nil in isrelevant
1 parent 4da9a5e commit 64e1f99

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

internal/mode/static/state/graph/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (g *Graph) IsNGFPolicyRelevant(
135135
}
136136

137137
if policy == nil {
138-
return false
138+
panic("policy cannot be nil")
139139
}
140140

141141
ref := policy.GetTargetRef()

internal/mode/static/state/graph/graph_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,9 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10221022
expRelevant: true,
10231023
},
10241024
{
1025-
name: "irrelevant; policy does not exist in graph and is nil (delete event)",
1025+
name: "irrelevant; policy does not exist in graph and is empty (delete event)",
10261026
graph: getGraph(),
1027-
policy: nil,
1027+
policy: &policiesfakes.FakePolicy{},
10281028
nsname: types.NamespacedName{Namespace: "diff", Name: "diff"},
10291029
expRelevant: false,
10301030
},
@@ -1108,3 +1108,16 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
11081108
})
11091109
}
11101110
}
1111+
1112+
func TestIsNGFPolicyRelevantPanics(t *testing.T) {
1113+
g := NewWithT(t)
1114+
graph := &Graph{}
1115+
nsname := types.NamespacedName{Namespace: "test", Name: "pol"}
1116+
gvk := schema.GroupVersionKind{Kind: "MyKind"}
1117+
1118+
isRelevant := func() {
1119+
_ = graph.IsNGFPolicyRelevant(nil, gvk, nsname)
1120+
}
1121+
1122+
g.Expect(isRelevant).To(Panic())
1123+
}

0 commit comments

Comments
 (0)