Skip to content

Commit

Permalink
fix: make ResultProperties.Policy nilable (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong authored Nov 27, 2024
1 parent c1be7d5 commit 075d0b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions internal/analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
_ "embed"
"fmt"
"github.com/snyk/code-client-go/sarif"
"io"
"net/http"
"strconv"
Expand Down Expand Up @@ -347,6 +348,19 @@ func TestAnalysis_RunAnalysis(t *testing.T) {

require.NoError(t, err)
assert.Equal(t, "scripts/db/migrations/20230811153738_add_generated_grouping_columns_to_collections_table.ts", actual.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI)

t.Run("should return policy details when provided", func(t *testing.T) {
expectedPolicy := sarif.SnykPolicyV1{
OriginalLevel: "warning",
OriginalSeverity: "critical",
Severity: "high",
}
assert.Equal(t, &expectedPolicy, actual.Sarif.Runs[0].Results[5].Properties.Policy)
})

t.Run("should default policy to nil when not provided", func(t *testing.T) {
assert.Nil(t, actual.Sarif.Runs[0].Results[0].Properties.Policy)
})
}

func TestAnalysis_RunAnalysis_TriggerFunctionError(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions internal/analysis/fake.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,12 @@
"type": "fixExamples"
}
],
"isAutofixable": false
"isAutofixable": false,
"snykPolicy/v1": {
"originalLevel": "warning",
"originalSeverity": "critical",
"severity": "high"
}
}
}
],
Expand Down Expand Up @@ -834,4 +839,4 @@
}
}
]
}
}
14 changes: 8 additions & 6 deletions sarif/sarif_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,20 @@ type Fingerprints struct {
Identity string `json:"identity"`
}

type SnykPolicyV1 struct {
OriginalLevel string `json:"originalLevel"`
OriginalSeverity string `json:"originalSeverity"`
Severity string `json:"severity"`
}

type ResultProperties struct {
PriorityScore int `json:"priorityScore"`
PriorityScoreFactors []struct {
Label bool `json:"label"`
Type string `json:"type"`
} `json:"priorityScoreFactors"`
IsAutofixable bool `json:"isAutofixable"`
Policy struct {
OriginalLevel string `json:"originalLevel"`
OriginalSeverity string `json:"originalSeverity"`
Severity string `json:"severity"`
} `json:"snykPolicy/v1"`
IsAutofixable bool `json:"isAutofixable"`
Policy *SnykPolicyV1 `json:"snykPolicy/v1,omitempty"`
}

type Result struct {
Expand Down

0 comments on commit 075d0b5

Please sign in to comment.