-
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.
Close the log Writer used for the std log
- Loading branch information
Showing
3 changed files
with
65 additions
and
5 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,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.k6.io/k6/lib/testutils/httpmultibin" | ||
) | ||
|
||
// SetOutput sets the global log so it is racy with other tests | ||
// | ||
//nolint:paralleltest | ||
func TestStdLogOutputIsSet(t *testing.T) { | ||
tb := httpmultibin.NewHTTPMultiBin(t) | ||
ts := newGlobalTestState(t) | ||
|
||
// Sometimes the Go runtime uses the standard log output to | ||
// log some messages directly. | ||
// It does when an invalid char is found in a Cookie. | ||
// Check for details https://github.com/grafana/k6/issues/711#issue-341414887 | ||
ts.stdIn = bytes.NewReader([]byte(tb.Replacer.Replace(` | ||
import http from 'k6/http'; | ||
export const options = { | ||
hosts: { | ||
"HTTPSBIN_DOMAIN": "HTTPSBIN_IP", | ||
}, | ||
insecureSkipTLSVerify: true, | ||
} | ||
export default function () { | ||
http.get("HTTPSBIN_URL/get", { | ||
"cookies": { | ||
"test": "\"" | ||
}, | ||
}) | ||
}`))) | ||
|
||
ts.args = []string{"k6", "version"} | ||
ts.args = []string{"k6", "run", "-i", "1", "-"} | ||
newRootCommand(ts.globalState).execute() | ||
|
||
entries := ts.loggerHook.Drain() | ||
require.Len(t, entries, 1) | ||
assert.Contains(t, entries[0].Message, "Cookie.Value; dropping invalid bytes") | ||
} |