-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from msugakov/update-format-support
Extend go-sarif with few more format elements
- Loading branch information
Showing
12 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package sarif | ||
|
||
import "time" | ||
|
||
// Invocation describes the runtime environment of the analysis tool run. | ||
type Invocation struct { | ||
StartTimeUTC *time.Time `json:"startTimeUtc,omitempty"` | ||
EndTimeUTC *time.Time `json:"endTimeUtc,omitempty"` | ||
ExecutionSuccessful bool `json:"executionSuccessful"` | ||
WorkingDirectory *ArtifactLocation `json:"workingDirectory,omitempty"` | ||
} | ||
|
||
// WithStartTimeUTC sets the instant when the invocation started and returns the same Invocation. | ||
func (i *Invocation) WithStartTimeUTC(startTime time.Time) *Invocation { | ||
startTimeUTC := startTime.UTC() | ||
i.StartTimeUTC = &startTimeUTC | ||
return i | ||
} | ||
|
||
// WithEndTimeUTC sets the instant when the invocation ended and returns the same Invocation. | ||
func (i *Invocation) WithEndTimeUTC(endTime time.Time) *Invocation { | ||
endTimeUTC := endTime.UTC() | ||
i.EndTimeUTC = &endTimeUTC | ||
return i | ||
} | ||
|
||
// WithWorkingDirectory sets the current working directory of the invocation and returns the same Invocation. | ||
func (i *Invocation) WithWorkingDirectory(workingDirectory *ArtifactLocation) *Invocation { | ||
i.WorkingDirectory = workingDirectory | ||
return i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sarif | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_invocation_with_time_utc(t *testing.T) { | ||
|
||
i := (&Invocation{ExecutionSuccessful: true}). | ||
WithStartTimeUTC(mustParseTime(t, "2020-12-31T23:59:59+01:00")). | ||
WithEndTimeUTC(mustParseTime(t, "2021-01-01T00:00:00+01:00")) | ||
|
||
assert.Equal(t, `{"startTimeUtc":"2020-12-31T22:59:59Z","endTimeUtc":"2020-12-31T23:00:00Z","executionSuccessful":true}`, getJsonString(i)) | ||
} | ||
|
||
func mustParseTime(t *testing.T, value string) time.Time { | ||
ts, err := time.Parse(time.RFC3339, value) | ||
require.NoError(t, err) | ||
return ts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
package sarif | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_create_multi_format_message_string(t *testing.T) { | ||
|
||
msg := NewMultiformatMessageString("mock plain text") | ||
|
||
assert.Equal(t, `{"text":"mock plain text"}`, getJsonString(msg)) | ||
} | ||
|
||
func Test_create_multi_format_message_string_with_markdown(t *testing.T) { | ||
|
||
msg := NewMultiformatMessageString("mock plain text"). | ||
WithMarkdown("mock markdown text") | ||
|
||
assert.Equal(t, `{"text":"mock plain text","markdown":"mock markdown text"}`, getJsonString(msg)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters