mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
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
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
ce8a09a4c0
commit
843fcd19d4
@ -97,21 +97,23 @@ func TestFixURL(t *testing.T) {
|
|||||||
{"No config", "", "", true, 1313, "//localhost:1313/"},
|
{"No config", "", "", true, 1313, "//localhost:1313/"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
b := newCommandsBuilder()
|
t.Run(test.TestName, func(t *testing.T) {
|
||||||
s := b.newServerCmd()
|
b := newCommandsBuilder()
|
||||||
v := viper.New()
|
s := b.newServerCmd()
|
||||||
baseURL := test.CLIBaseURL
|
v := viper.New()
|
||||||
v.Set("baseURL", test.CfgBaseURL)
|
baseURL := test.CLIBaseURL
|
||||||
s.serverAppend = test.AppendPort
|
v.Set("baseURL", test.CfgBaseURL)
|
||||||
s.serverPort = test.Port
|
s.serverAppend = test.AppendPort
|
||||||
result, err := s.fixURL(v, baseURL, s.serverPort)
|
s.serverPort = test.Port
|
||||||
if err != nil {
|
result, err := s.fixURL(v, baseURL, s.serverPort)
|
||||||
t.Errorf("Test #%d %s: unexpected error %s", i, test.TestName, err)
|
if err != nil {
|
||||||
}
|
t.Errorf("Unexpected error %s", err)
|
||||||
if result != test.Result {
|
}
|
||||||
t.Errorf("Test #%d %s: expected %q, got %q", i, test.TestName, test.Result, result)
|
if result != test.Result {
|
||||||
}
|
t.Errorf("Expected %q, got %q", test.Result, result)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user