summaryrefslogtreecommitdiffhomepage
path: root/commands/server.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-04-11 09:38:58 +0200
committerBjørn Erik Pedersen <[email protected]>2018-04-11 09:51:07 +0200
commita7d00fc39e87a5cac99b3a2380f5cc8c135d2b4b (patch)
tree952bd16111a0a56225d2b6dc2c726556e4392503 /commands/server.go
parent1e233b1c4598fd8cbce7da8a67bf2c4918c6047e (diff)
downloadhugo-a7d00fc39e87a5cac99b3a2380f5cc8c135d2b4b.tar.gz
hugo-a7d00fc39e87a5cac99b3a2380f5cc8c135d2b4b.zip
commands: Add basic server test
See #4598
Diffstat (limited to 'commands/server.go')
-rw-r--r--commands/server.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/commands/server.go b/commands/server.go
index 6ede49417..5500526e8 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -39,6 +39,11 @@ import (
)
type serverCmd struct {
+ // Can be used to stop the server. Useful in tests
+ stop <-chan bool
+ // Can be used to receive notification about when the server is started. Useful in tests.
+ started chan<- bool
+
disableLiveReload bool
navigateToChanged bool
renderToDisk bool
@@ -55,7 +60,11 @@ type serverCmd struct {
}
func newServerCmd() *serverCmd {
- cc := &serverCmd{}
+ return newServerCmdSignaled(nil, nil)
+}
+
+func newServerCmdSignaled(stop <-chan bool, started chan<- bool) *serverCmd {
+ cc := &serverCmd{stop: stop, started: started}
cc.baseBuilderCmd = newBuilderCmd(&cobra.Command{
Use: "server",
@@ -394,9 +403,20 @@ func (c *commandeer) serve(s *serverCmd) error {
}()
}
+ if s.started != nil {
+ s.started <- true
+ }
+
jww.FEEDBACK.Println("Press Ctrl+C to stop")
- <-sigs
+ if s.stop != nil {
+ select {
+ case <-sigs:
+ case <-s.stop:
+ }
+ } else {
+ <-sigs
+ }
return nil
}