mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
67df33f500
First step to use initialisms that golint suggests, for example: Line 116: func GetHtmlRenderer should be GetHTMLRenderer as see on http://goreportcard.com/report/spf13/hugo Thanks to @bep for the idea! Note that command-line flags (cobra and pflag) as well as struct fields like .BaseUrl and .Url that are used in Go HTML templates need more work to maintain backward-compatibility, and thus are NOT yet dealt with in this commit. First step in fixing #959.
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func TestFixURL(t *testing.T) {
|
|
type data struct {
|
|
TestName string
|
|
CLIBaseURL string
|
|
CfgBaseURL string
|
|
AppendPort bool
|
|
Port int
|
|
Result string
|
|
}
|
|
tests := []data{
|
|
{"Basic http localhost", "", "http://foo.com", true, 1313, "http://localhost:1313/"},
|
|
{"Basic https production, http localhost", "", "https://foo.com", true, 1313, "http://localhost:1313/"},
|
|
{"Basic subdir", "", "http://foo.com/bar", true, 1313, "http://localhost:1313/bar/"},
|
|
{"Basic production", "http://foo.com", "http://foo.com", false, 80, "http://foo.com/"},
|
|
{"Production subdir", "http://foo.com/bar", "http://foo.com/bar", false, 80, "http://foo.com/bar/"},
|
|
{"No http", "", "foo.com", true, 1313, "http://localhost:1313/"},
|
|
{"Override configured port", "", "foo.com:2020", true, 1313, "http://localhost:1313/"},
|
|
{"No http production", "foo.com", "foo.com", false, 80, "http://foo.com/"},
|
|
{"No http production with port", "foo.com", "foo.com", true, 2020, "http://foo.com:2020/"},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
BaseURL = test.CLIBaseURL
|
|
viper.Set("BaseURL", test.CfgBaseURL)
|
|
serverAppend = test.AppendPort
|
|
serverPort = test.Port
|
|
result, err := fixURL(BaseURL)
|
|
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)
|
|
}
|
|
}
|
|
}
|