-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use require.NoError instead of assert.NoError
require.NoError will stop a test if the variable passed to it contains an error whereas assert.NoError will just report the existence of an error. Signed-off-by: Pavlos Tzianos <[email protected]>
- Loading branch information
Showing
36 changed files
with
208 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
|
||
"github.com/ocurity/dracon/components/consumers/defectdojo/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDojoClient(t *testing.T) { | ||
|
@@ -17,13 +18,13 @@ func TestDojoClient(t *testing.T) { | |
assert.Equal(t, r.RequestURI, "/users") | ||
called = true | ||
_, err := w.Write([]byte(`{"count":1,"next":null,"previous":null,"results":[{"id":1,"username":"admin","first_name":"Admin","last_name":"User","email":"[email protected]","last_login":"2022-05-31T20:26:54.928778Z","is_active":true,"is_superuser":true}]}`)) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
})) | ||
authToken := "foo" | ||
authUser := "bar" | ||
client, err := DojoClient(mockTs.URL, authToken, authUser) | ||
c := &Client{host: mockTs.URL, apiToken: authToken, user: authUser} | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
assert.True(t, called) | ||
assert.Equal(t, client, c) | ||
} | ||
|
@@ -37,7 +38,7 @@ func TestCreateFinding(t *testing.T) { | |
assert.Equal(t, r.RequestURI, "/findings") | ||
|
||
b, err := io.ReadAll(r.Body) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
|
||
var actual, exp types.FindingCreateRequest | ||
exp = types.FindingCreateRequest{ | ||
|
@@ -56,11 +57,11 @@ func TestCreateFinding(t *testing.T) { | |
Tags: []string{"tests"}, | ||
Date: "2006-01-02", | ||
} | ||
assert.NoError(t, json.Unmarshal(b, &actual)) | ||
require.NoError(t, json.Unmarshal(b, &actual)) | ||
assert.Equal(t, actual, exp) | ||
|
||
_, err = w.Write([]byte(expected)) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
})) | ||
|
||
c := &Client{host: mockTs.URL, apiToken: "test", user: ""} | ||
|
@@ -74,7 +75,7 @@ func TestCreateFinding(t *testing.T) { | |
1, | ||
1, | ||
0, 0, false, false, false, 3.9) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
assert.True(t, called) | ||
} | ||
|
||
|
@@ -86,10 +87,10 @@ func TestCreateEngagement(t *testing.T) { | |
assert.Equal(t, r.RequestURI, "/engagements") | ||
|
||
b, err := io.ReadAll(r.Body) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
|
||
var engagement types.EngagementRequest | ||
assert.NoError(t, json.Unmarshal(b, &engagement)) | ||
require.NoError(t, json.Unmarshal(b, &engagement)) | ||
|
||
expectedEngagement := types.EngagementRequest{ | ||
Tags: []string{"foo.git/somesha"}, | ||
|
@@ -102,11 +103,11 @@ func TestCreateEngagement(t *testing.T) { | |
assert.Equal(t, expectedEngagement, engagement) | ||
|
||
_, err = w.Write([]byte(`{"id":4,"tags":["foo.git/somesha"],"name":"dracon scan foo","description":null,"version":"string","first_contacted":null,"target_start":"2022-06-01","target_end":"2022-06-01","reason":null,"updated":"2022-06-01T16:29:18.965507Z","created":"2022-06-01T16:29:18.908694Z","active":true,"tracker":null,"test_strategy":null,"threat_model":true,"api_test":true,"pen_test":true,"check_list":true,"status":"","progress":"threat_model","tmodel_path":"none","done_testing":false,"engagement_type":"Interactive","build_id":"foo","commit_hash":null,"branch_tag":null,"source_code_management_uri":null,"deduplication_on_engagement":false,"lead":null,"requester":null,"preset":null,"report_type":null,"product":2,"build_server":null,"source_code_management_server":null,"orchestration_engine":null,"notes":[],"files":[],"risk_acceptance":[]}`)) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
})) | ||
|
||
c := &Client{host: mockTs.URL, apiToken: "test", user: ""} | ||
_, err := c.CreateEngagement("dracon scan foo", "2022-06-01", []string{"foo.git/somesha"}, 2) | ||
assert.NoError(t, err) | ||
require.NoError(t, err) | ||
assert.True(t, called) | ||
} |
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
Oops, something went wrong.