-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure thresholds parsing is skipped on --no-thresholds
This commit ensures that thresholds parsing is a separate step, done only when the `--no-threshold` flag is not set. Note that this commit deactivates tests that assumed `Thresholds.UnmarshalJSON` to effectively parse the thresholds.
- Loading branch information
Showing
11 changed files
with
333 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.k6.io/k6/errext" | ||
"go.k6.io/k6/errext/exitcodes" | ||
"go.k6.io/k6/lib/testutils" | ||
) | ||
|
||
func TestArchiveThresholds(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
name string | ||
noThresholds bool | ||
testFilename string | ||
|
||
wantErr bool | ||
}{ | ||
{ | ||
name: "archive should fail with exit status 104 on a malformed threshold expression", | ||
noThresholds: false, | ||
testFilename: "testdata/thresholds/malformed_expression.js", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "archive should on a malformed threshold expression but --no-thresholds flag set", | ||
noThresholds: true, | ||
testFilename: "testdata/thresholds/malformed_expression.js", | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cmd := getArchiveCmd(testutils.NewLogger(t), newCommandFlags()) | ||
filename, err := filepath.Abs(testCase.testFilename) | ||
require.NoError(t, err) | ||
args := []string{filename} | ||
if testCase.noThresholds { | ||
args = append(args, "--no-thresholds") | ||
} | ||
cmd.SetArgs(args) | ||
wantExitCode := exitcodes.InvalidConfig | ||
|
||
var gotErrExt errext.HasExitCode | ||
gotErr := cmd.Execute() | ||
|
||
assert.Equal(t, | ||
testCase.wantErr, | ||
gotErr != nil, | ||
"archive command error = %v, wantErr %v", gotErr, testCase.wantErr, | ||
) | ||
|
||
if testCase.wantErr { | ||
require.ErrorAs(t, gotErr, &gotErrExt) | ||
assert.Equalf(t, wantExitCode, gotErrExt.ExitCode(), | ||
"status code must be %d", wantExitCode, | ||
) | ||
} | ||
}) | ||
} | ||
} |
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
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,11 @@ | ||
export const options = { | ||
thresholds: { | ||
http_reqs: ["foo&0"], // Counter | ||
}, | ||
}; | ||
|
||
export default function () { | ||
console.log( | ||
"asserting that a malformed threshold fails with exit code 104 (Invalid config)" | ||
); | ||
} |
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
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.