Skip to content

Commit

Permalink
Correctly set the "name" of scripts ran through the shortcut urls
Browse files Browse the repository at this point in the history
fixes #1236
  • Loading branch information
mstoykov committed Nov 13, 2019
1 parent 91a6828 commit 82d6dd4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stats/cloud/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func New(conf Config, src *loader.SourceData, opts lib.Options, version string)
}

if !conf.Name.Valid || conf.Name.String == "" {
conf.Name = null.StringFrom(filepath.Base(src.URL.Path))
conf.Name = null.StringFrom(filepath.Base(src.URL.String()))
}
if conf.Name.String == "-" {
conf.Name = null.StringFrom(TestName)
Expand Down
48 changes: 48 additions & 0 deletions stats/cloud/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,51 @@ func TestCloudCollectorRecvIterLIAllIterations(t *testing.T) {
wg.Wait()
require.True(t, gotIterations)
}

func TestNewName(t *testing.T) {
t.Parallel()
mustParse := func(u string) *url.URL {
result, err := url.Parse(u)
require.NoError(t, err)
return result
}

cases := []struct {
url *url.URL
expected string
}{
{
url: &url.URL{
Opaque: "github.com/loadimpact/k6/samples/http_get.js",
},
expected: "http_get.js",
},
{
url: mustParse("http://github.com/loadimpact/k6/samples/http_get.js"),
expected: "http_get.js",
},
{
url: mustParse("file://home/user/k6/samples/http_get.js"),
expected: "http_get.js",
},
{
url: mustParse("file://C:/home/user/k6/samples/http_get.js"),
expected: "http_get.js",
},
}

for _, testCase := range cases {
testCase := testCase

t.Run(testCase.url.String(), func(t *testing.T) {
script := &loader.SourceData{
URL: testCase.url,
}
collector, err := New(NewConfig(), script, lib.Options{
Duration: types.NullDurationFrom(1 * time.Second),
}, "1.0")
require.NoError(t, err)
require.Equal(t, collector.config.Name.String, testCase.expected)
})
}
}

0 comments on commit 82d6dd4

Please sign in to comment.