Skip to content

Commit 389db7f

Browse files
author
James Alseth
authored
Fix getPolicyIDFromMetadata never returning an error (#6)
1 parent 4f2d1bb commit 389db7f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func runConftestTest() ([]jsonCheckResult, error) {
292292

293293
func getPolicyIDFromMetadata(metadata map[string]interface{}, policyIDKey string) (string, error) {
294294
details := metadata["details"].(map[string]interface{})
295-
if details[policyIDKey] == "" {
295+
if details[policyIDKey] == nil {
296296
return "", fmt.Errorf("empty policyID key")
297297
}
298298

main_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,16 @@ func TestGetPolicyIDFromMetadata(t *testing.T) {
146146
t.Errorf("output %v did not match expected %v", actual, expected)
147147
}
148148
}
149+
150+
func TestGetPolicyIDFromMetadata_Empty(t *testing.T) {
151+
metadata := map[string]interface{}{
152+
"details": map[string]interface{}{
153+
"test": "TEST",
154+
},
155+
}
156+
157+
_, err := getPolicyIDFromMetadata(metadata, "policyID")
158+
if err == nil {
159+
t.Errorf("should error when policyIDKey does not exist")
160+
}
161+
}

0 commit comments

Comments
 (0)