mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-27 22:41:30 +00:00
f21e2f25c9
All config variables starts with low-case and uses camelCase. If there is abbreviation at the beginning of the name, the whole abbreviation will be written in low-case. If there is abbreviation at the end of the name, the whole abbreviation will be written in upper-case. For example, rssURI.
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
// Copyright 2015 The Hugo Authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func TestFixURL(t *testing.T) {
|
|
defer viper.Reset()
|
|
|
|
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, "//localhost:1313/"},
|
|
{"Override configured port", "", "foo.com:2020", true, 1313, "//localhost:1313/"},
|
|
{"No http production", "foo.com", "foo.com", false, 80, "//foo.com/"},
|
|
{"No http production with port", "foo.com", "foo.com", true, 2020, "//foo.com:2020/"},
|
|
{"No config", "", "", true, 1313, "//localhost:1313/"},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
viper.Reset()
|
|
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)
|
|
}
|
|
}
|
|
}
|