Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message checking #1249

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,25 +648,26 @@ func TestVUIntegrationInsecureRequests(t *testing.T) {
}{
"Null": {
lib.Options{},
"GoError: Get https://expired.badssl.com/: x509: certificate has expired or is not yet valid",
"x509: certificate has expired or is not yet valid",
},
"False": {
lib.Options{InsecureSkipTLSVerify: null.BoolFrom(false)},
"GoError: Get https://expired.badssl.com/: x509: certificate has expired or is not yet valid",
"x509: certificate has expired or is not yet valid",
},
"True": {
lib.Options{InsecureSkipTLSVerify: null.BoolFrom(true)},
"",
},
}
for name, data := range testdata {
data := data
t.Run(name, func(t *testing.T) {
r1, err := getSimpleRunner("/script.js", `
import http from "k6/http";
export default function() { http.get("https://expired.badssl.com/"); }
`)
require.NoError(t, err)
r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)}.Apply(data.opts))
require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)}.Apply(data.opts)))

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
require.NoError(t, err)
Expand All @@ -681,7 +682,8 @@ func TestVUIntegrationInsecureRequests(t *testing.T) {
}
err = vu.RunOnce(context.Background())
if data.errMsg != "" {
assert.EqualError(t, err, data.errMsg)
require.NotNil(t, err)
mstoykov marked this conversation as resolved.
Show resolved Hide resolved
assert.Contains(t, err.Error(), data.errMsg)
} else {
assert.NoError(t, err)
}
Expand All @@ -703,10 +705,10 @@ func TestVUIntegrationBlacklistOption(t *testing.T) {
if !assert.NoError(t, err) {
return
}
r1.SetOptions(lib.Options{
require.NoError(t, r1.SetOptions(lib.Options{
Throw: null.BoolFrom(true),
BlacklistIPs: []*lib.IPNet{cidr},
})
}))

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
if !assert.NoError(t, err) {
Expand All @@ -721,7 +723,8 @@ func TestVUIntegrationBlacklistOption(t *testing.T) {
return
}
err = vu.RunOnce(context.Background())
assert.EqualError(t, err, "GoError: Get http://10.1.2.3/: IP (10.1.2.3) is in a blacklisted range (10.0.0.0/8)")
require.NotNil(t, err)
assert.Contains(t, err.Error(), "IP (10.1.2.3) is in a blacklisted range (10.0.0.0/8)")
})
}
}
Expand Down Expand Up @@ -756,7 +759,8 @@ func TestVUIntegrationBlacklistScript(t *testing.T) {
return
}
err = vu.RunOnce(context.Background())
assert.EqualError(t, err, "GoError: Get http://10.1.2.3/: IP (10.1.2.3) is in a blacklisted range (10.0.0.0/8)")
require.NotNil(t, err)
assert.Contains(t, err.Error(), "IP (10.1.2.3) is in a blacklisted range (10.0.0.0/8)")
})
}
}
Expand Down Expand Up @@ -830,7 +834,7 @@ func TestVUIntegrationTLSConfig(t *testing.T) {
},
"UnsupportedCipherSuite": {
lib.Options{TLSCipherSuites: &lib.TLSCipherSuites{tls.TLS_RSA_WITH_RC4_128_SHA}},
"GoError: Get https://sha256.badssl.com/: remote error: tls: handshake failure",
"remote error: tls: handshake failure",
},
"NullVersion": {
lib.Options{},
Expand All @@ -842,10 +846,11 @@ func TestVUIntegrationTLSConfig(t *testing.T) {
},
"UnsupportedVersion": {
lib.Options{TLSVersion: &lib.TLSVersions{Min: tls.VersionSSL30, Max: tls.VersionSSL30}},
"GoError: Get https://sha256.badssl.com/: " + unsupportedVersionErrorMsg,
unsupportedVersionErrorMsg,
},
}
for name, data := range testdata {
data := data
t.Run(name, func(t *testing.T) {
r1, err := getSimpleRunner("/script.js", `
import http from "k6/http";
Expand All @@ -854,7 +859,7 @@ func TestVUIntegrationTLSConfig(t *testing.T) {
if !assert.NoError(t, err) {
return
}
r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)}.Apply(data.opts))
require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)}.Apply(data.opts)))

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
if !assert.NoError(t, err) {
Expand All @@ -872,7 +877,8 @@ func TestVUIntegrationTLSConfig(t *testing.T) {
}
err = vu.RunOnce(context.Background())
if data.errMsg != "" {
assert.EqualError(t, err, data.errMsg)
require.NotNil(t, err)
assert.Contains(t, err.Error(), data.errMsg)
} else {
assert.NoError(t, err)
}
Expand All @@ -894,10 +900,10 @@ func TestVUIntegrationHTTP2(t *testing.T) {
if !assert.NoError(t, err) {
return
}
r1.SetOptions(lib.Options{
require.NoError(t, r1.SetOptions(lib.Options{
Throw: null.BoolFrom(true),
SystemTags: stats.NewSystemTagSet(stats.TagProto),
})
}))

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
if !assert.NoError(t, err) {
Expand Down Expand Up @@ -1150,10 +1156,10 @@ func TestVUIntegrationClientCerts(t *testing.T) {
if !assert.NoError(t, err) {
return
}
r1.SetOptions(lib.Options{
require.NoError(t, r1.SetOptions(lib.Options{
Throw: null.BoolFrom(true),
InsecureSkipTLSVerify: null.BoolFrom(true),
})
}))

t.Run("Unauthenticated", func(t *testing.T) {
r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
Expand All @@ -1175,7 +1181,7 @@ func TestVUIntegrationClientCerts(t *testing.T) {
}
})

r1.SetOptions(lib.Options{
require.NoError(t, r1.SetOptions(lib.Options{
TLSAuth: []*lib.TLSAuth{
{
TLSAuthFields: lib.TLSAuthFields{
Expand All @@ -1199,7 +1205,7 @@ func TestVUIntegrationClientCerts(t *testing.T) {
},
},
},
})
}))

t.Run("Authenticated", func(t *testing.T) {
r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
Expand Down