Skip to content

Commit

Permalink
Update response (#3)
Browse files Browse the repository at this point in the history
* don't error if no output was returned from snyk scan diff

* update coverage
  • Loading branch information
DI-Tony-Reed authored Oct 11, 2024
1 parent 1d02b83 commit 81e5ec9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ func (j JSONDiff) FindDifferences() (string, error) {
return "", err
}

if len(output) == 0 {
return "No differences found.", nil
}

return output, errors.New("new vulnerability(s) found")
}
54 changes: 53 additions & 1 deletion compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,59 @@ func TestJSONDiff_FindDifferences(t *testing.T) {
}

output, err := j.FindDifferences()
if err == nil || output != "" {
if err != nil || output != "No differences found." {
t.Errorf("JSONDiff.FindDifferences() error = %v", err)
}
}

func TestJSONDiff_FindDifferences_Error(t *testing.T) {
j := JSONDiff{
File1: File{
Bytes: []byte(`{"runs": "value1"}`),
Map: map[string]interface{}{
"runs": []interface{}{
map[string]interface{}{
"results": []interface{}{},
},
},
},
},
File2: File{
Bytes: []byte(`{"runs": "value2"}`),
Map: map[string]interface{}{
"runs": []interface{}{
map[string]interface{}{
"results": []interface{}{
map[string]interface{}{
"fingerprints": map[string]interface{}{
"identity": "67890",
},
"level": "error",
"message": map[string]interface{}{
"text": "New Issue",
},
"locations": []interface{}{
map[string]interface{}{
"physicalLocation": map[string]interface{}{
"artifactLocation": map[string]interface{}{
"uri": "file2.go",
},
"region": map[string]interface{}{
"startLine": 20.0,
},
},
},
},
},
},
},
},
},
},
}

output, err := j.FindDifferences()
if err == nil || len(output) == 0 {
t.Errorf("JSONDiff.FindDifferences() wanted error, got = %v and output %v", err, output)
}
}

0 comments on commit 81e5ec9

Please sign in to comment.