summaryrefslogtreecommitdiffstats
path: root/commands/server_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-11 09:38:58 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-11 09:51:07 +0200
commita7d00fc39e87a5cac99b3a2380f5cc8c135d2b4b (patch)
tree952bd16111a0a56225d2b6dc2c726556e4392503 /commands/server_test.go
parent1e233b1c4598fd8cbce7da8a67bf2c4918c6047e (diff)
commands: Add basic server test
See #4598
Diffstat (limited to 'commands/server_test.go')
-rw-r--r--commands/server_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/commands/server_test.go b/commands/server_test.go
index 8940eb078..b17addf6b 100644
--- a/commands/server_test.go
+++ b/commands/server_test.go
@@ -14,11 +14,60 @@
package commands
import (
+ "fmt"
+ "net/http"
+ "os"
"testing"
+ "time"
+
+ "github.com/gohugoio/hugo/helpers"
"github.com/spf13/viper"
+ "github.com/stretchr/testify/require"
)
+func TestServer(t *testing.T) {
+ assert := require.New(t)
+ dir, err := createSimpleTestSite(t)
+ assert.NoError(err)
+
+ // Let us hope that this port is available on all systems ...
+ port := 1331
+
+ defer func() {
+ os.RemoveAll(dir)
+ }()
+
+ stop, started := make(chan bool), make(chan bool)
+
+ scmd := newServerCmdSignaled(stop, started)
+
+ cmd := scmd.getCommand()
+ cmd.SetArgs([]string{"-s=" + dir, fmt.Sprintf("-p=%d", port)})
+
+ go func() {
+ _, err = cmd.ExecuteC()
+ assert.NoError(err)
+ }()
+
+ select {
+ case <-started:
+ case <-time.After(2 * time.Second):
+ t.Fatal("server start took too long")
+ }
+
+ resp, err := http.Get("http://localhost:1331/")
+ assert.NoError(err)
+ defer resp.Body.Close()
+ homeContent := helpers.ReaderToString(resp.Body)
+
+ assert.Contains(homeContent, "List: Hugo Commands")
+
+ // Stop the server.
+ stop <- true
+
+}
+
func TestFixURL(t *testing.T) {
type data struct {
TestName string