Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Sep 14, 2023
1 parent 8783e6a commit 5e8bccd
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion xray/utils/sarifutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,24 @@ func TestGetLocationSnippet(t *testing.T) {
}

func TestSetLocationSnippet(t *testing.T) {
tests := []struct {
location *sarif.Location
expectedOutput string
}{
{
location: nil,
expectedOutput: "",
},
{
location: GetDummyLocation("filename", 1, 2, 3, 4, "snippet"),
expectedOutput: "changedSnippet",
},
}

for _, test := range tests {
SetLocationSnippet(test.location, test.expectedOutput)
assert.Equal(t, test.expectedOutput, GetLocationSnippet(test.location))
}
}

func TestGetLocationFileName(t *testing.T) {
Expand Down Expand Up @@ -130,15 +147,48 @@ func TestGetRelativeLocationFileName(t *testing.T) {
location *sarif.Location
invocations []*sarif.Invocation
expectedOutput string
}{}
}{
{
location: GetDummyLocation("file:///root/someDir/another/file", 1, 2, 3, 4, "snippet"),
invocations: []*sarif.Invocation{},
expectedOutput: "root/someDir/another/file",
},
{
location: GetDummyLocation("file:///root/someDir/another/file", 1, 2, 3, 4, "snippet"),
invocations: []*sarif.Invocation{{WorkingDirectory: sarif.NewSimpleArtifactLocation("/not/relevant")}},
expectedOutput: "root/someDir/another/file",
},
{
location: GetDummyLocation("file:///root/someDir/another/file", 1, 2, 3, 4, "snippet"),
invocations: []*sarif.Invocation{{WorkingDirectory: sarif.NewSimpleArtifactLocation("/root/someDir/")}},
expectedOutput: "another/file",
},
}

for _, test := range tests {
assert.Equal(t, test.expectedOutput, GetRelativeLocationFileName(test.location, test.invocations))
}
}

func TestSetLocationFileName(t *testing.T) {
tests := []struct {
location *sarif.Location
expectedOutput string
}{
{
location: nil,
expectedOutput: "",
},
{
location: GetDummyLocation("filename", 1, 2, 3, 4, "snippet"),
expectedOutput: "changedFilename",
},
}

for _, test := range tests {
SetLocationFileName(test.location, test.expectedOutput)
assert.Equal(t, test.expectedOutput, GetLocationFileName(test.location))
}
}

func TestGetLocationRegion(t *testing.T) {
Expand Down

0 comments on commit 5e8bccd

Please sign in to comment.