diff options
author | Nate Finch <nate.finch@gmail.com> | 2014-08-22 07:59:59 -0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-08-25 11:51:51 -0400 |
commit | a31edb3388606eb231261780d91e1324c50b2953 (patch) | |
tree | 3b4189b0240765210b3fce4525665b28d209f5d4 /commands/server_test.go | |
parent | 4b979b17cc3af0d6da3026a2ca02b525133b6d3f (diff) |
Support subdir in baseurl.
Mainly this was a change to helpers.MakePermalink, but to get the local server to run correctly,
we needed to redirect the path of the request from /foo to /. In addition, I added tests for the
server's code for fixing up the base url with different config file & CLI options.
Diffstat (limited to 'commands/server_test.go')
-rw-r--r-- | commands/server_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/commands/server_test.go b/commands/server_test.go new file mode 100644 index 000000000..d84579642 --- /dev/null +++ b/commands/server_test.go @@ -0,0 +1,42 @@ +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 localhost", "", "http://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", err) + } + if result != test.Result { + t.Errorf("Test #%d %s: expected %q, got %q", i, test.TestName, test.Result, result) + } + } +} |