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

Exposes runner.newConfig publicly #231

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ func WithTemplateFuncs(funcMap template.FuncMap) Option {
}
}

func newConfig(call, host string, options ...Option) (*RunConfig, error) {
// NewConfig creates a new RunConfig from the options passed
func NewConfig(call, host string, options ...Option) (*RunConfig, error) {
call = strings.TrimSpace(call)
host = strings.TrimSpace(host)

Expand Down
32 changes: 16 additions & 16 deletions runner/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (

func TestRunConfig_newRunConfig(t *testing.T) {
t.Run("fail with empty call", func(t *testing.T) {
c, err := newConfig(" ", "localhost:50050")
c, err := NewConfig(" ", "localhost:50050")

assert.Error(t, err)
assert.Nil(t, c)
})

t.Run("fail with empty host ", func(t *testing.T) {
c, err := newConfig(" call ", " ")
c, err := NewConfig(" call ", " ")

assert.Error(t, err)
assert.Nil(t, c)
})

t.Run("fail with invalid extension", func(t *testing.T) {
c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.bin", []string{}),
)

Expand All @@ -36,7 +36,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("without any options should have defaults", func(t *testing.T) {
c, err := newConfig(" call ", " localhost:50050 ",
c, err := NewConfig(" call ", " localhost:50050 ",
WithProtoFile("testdata/data.proto", []string{}),
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("with options", func(t *testing.T) {
c, err := newConfig(
c, err := NewConfig(
"call", "localhost:50050",
WithInsecure(true),
WithTotalRequests(100),
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("with binary data, protoset and metadata file", func(t *testing.T) {
c, err := newConfig(
c, err := NewConfig(
"call", "localhost:50050",
WithCertificate("../testdata/localhost.crt", "../testdata/localhost.key"),
WithServerNameOverride("cname"),
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
rmd := make(map[string]string)
rmd["auth"] = "bizbaz"

c, err := newConfig(
c, err := NewConfig(
"call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithCertificate("../testdata/localhost.crt", "../testdata/localhost.key"),
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("with binary data from file", func(t *testing.T) {
c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithBinaryDataFromFile("../testdata/hello_request_data.bin"),
)
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("with data from file", func(t *testing.T) {
c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithDataFromFile("../testdata/data.json"),
)
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
file, _ := os.Open("../testdata/data.json")
defer file.Close()

c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithDataFromReader(file),
)
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
file, _ := os.Open("../testdata/data.json")
defer file.Close()

c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithDataFromReader(file),
WithConnections(5),
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
file, _ := os.Open("../testdata/data.json")
defer file.Close()

c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithProtoFile("testdata/data.proto", []string{}),
WithDataFromReader(file),
WithConcurrency(5),
Expand All @@ -383,7 +383,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
filename := "../testdata/config.json"

t.Run("from file", func(t *testing.T) {
c, err := newConfig("", "",
c, err := NewConfig("", "",
WithConfigFromFile(filename))
assert.Nil(t, err)
assert.Equal(t, "helloworld.Greeter.SayHello", c.call)
Expand All @@ -401,7 +401,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
})

t.Run("from file 2", func(t *testing.T) {
c, err := newConfig("", "",
c, err := NewConfig("", "",
WithConfigFromFile("../testdata/config5.toml"))
assert.Nil(t, err)
assert.Equal(t, "helloworld.Greeter.SayHello", c.call)
Expand All @@ -422,7 +422,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {
file, _ := os.Open(filename)
defer file.Close()

c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithConfigFromReader(file))
assert.Nil(t, err)
assert.Equal(t, "helloworld.Greeter.SayHello", c.call)
Expand All @@ -445,7 +445,7 @@ func TestRunConfig_newRunConfig(t *testing.T) {

var config Config
_ = json.NewDecoder(file).Decode(&config)
c, err := newConfig("call", "localhost:50050",
c, err := NewConfig("call", "localhost:50050",
WithConfig(&config))
assert.Nil(t, err)
assert.Equal(t, "helloworld.Greeter.SayHello", c.call)
Expand Down
2 changes: 1 addition & 1 deletion runner/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestReport_MarshalJSON(t *testing.T) {

func TestReport_CorrectDetails(t *testing.T) {
callResultsChan := make(chan *callResult)
config, _ := newConfig("call", "host")
config, _ := NewConfig("call", "host")
reporter := newReporter(callResultsChan, config)

go reporter.Run()
Expand Down
2 changes: 1 addition & 1 deletion runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// WithInsecure(true),
// )
func Run(call, host string, options ...Option) (*Report, error) {
c, err := newConfig(call, host, options...)
c, err := NewConfig(call, host, options...)

if err != nil {
return nil, err
Expand Down