diff options
author | Anton Harniakou <anton.harniakou@gmail.com> | 2019-01-07 19:25:27 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-01-08 14:54:11 +0100 |
commit | 843fcd19d4d97bac979410a4e0abed72586a0aa0 (patch) | |
tree | e294f8a21a06d54577fca09f4edce083baa4e531 /commands/server_test.go | |
parent | ce8a09a4c0661dece931ab1173e4f09e8e04aa38 (diff) |
Use subtests with server_test.go
Use Golang's subtests to provide a convenient way
to run specific tests.
Example:
go test -run=TestFixURL/Basic_production
Diffstat (limited to 'commands/server_test.go')
-rw-r--r-- | commands/server_test.go | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/commands/server_test.go b/commands/server_test.go index 24f203ad0..53a240145 100644 --- a/commands/server_test.go +++ b/commands/server_test.go @@ -97,21 +97,23 @@ func TestFixURL(t *testing.T) { {"No config", "", "", true, 1313, "//localhost:1313/"}, } - for i, test := range tests { - b := newCommandsBuilder() - s := b.newServerCmd() - v := viper.New() - baseURL := test.CLIBaseURL - v.Set("baseURL", test.CfgBaseURL) - s.serverAppend = test.AppendPort - s.serverPort = test.Port - result, err := s.fixURL(v, baseURL, s.serverPort) - if err != nil { - t.Errorf("Test #%d %s: unexpected error %s", i, test.TestName, err) - } - if result != test.Result { - t.Errorf("Test #%d %s: expected %q, got %q", i, test.TestName, test.Result, result) - } + for _, test := range tests { + t.Run(test.TestName, func(t *testing.T) { + b := newCommandsBuilder() + s := b.newServerCmd() + v := viper.New() + baseURL := test.CLIBaseURL + v.Set("baseURL", test.CfgBaseURL) + s.serverAppend = test.AppendPort + s.serverPort = test.Port + result, err := s.fixURL(v, baseURL, s.serverPort) + if err != nil { + t.Errorf("Unexpected error %s", err) + } + if result != test.Result { + t.Errorf("Expected %q, got %q", test.Result, result) + } + }) } } |