Skip to content

Commit

Permalink
WIP: Write test, confirm it working
Browse files Browse the repository at this point in the history
  • Loading branch information
baalimago committed Oct 8, 2024
1 parent b41badb commit b9036ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type command struct {
flagset *flag.FlagSet
fileserver Fileserver

cacheControl *string
cacheControl *string
certificatePath *string
}

func Command() *command {
Expand Down Expand Up @@ -127,6 +128,7 @@ func (c *command) Flagset() *flag.FlagSet {
c.wsPath = fs.String("wsPort", "/delta-streamer-ws", "the path which the delta streamer websocket should be hosted on")
c.forceReload = fs.Bool("forceReload", false, "set to true if you wish to reload all attached browser pages on any file change")
c.cacheControl = fs.String("cacheControl", "no-cache", "set to configure the cache-control header")
c.certificatePath = fs.String("certPath", "", "set to some existing cert which should be used for TLS (https)")
c.flagset = fs
return fs
}
26 changes: 26 additions & 0 deletions cmd/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,30 @@ func TestRun(t *testing.T) {
got := resp.Header.Get("Cache-Control")
testboil.FailTestIfDiff(t, got, want)
})

t.Run("it should serve with tls if cert is specified", func(t *testing.T) {
cmd := setup()
ctx, ctxCancel := context.WithCancel(context.Background())
t.Cleanup(ctxCancel)
port := 13337
cmd.port = &port
cmd.certificatePath = "TODO"

ready := make(chan struct{})
go func() {
close(ready)
err := cmd.Run(ctx)
if err != nil {
t.Errorf("Run returned error: %v", err)
}
}()
<-ready
time.Sleep(time.Millisecond)
resp, err := http.Get(fmt.Sprintf("http://localhost:%v", port))
if err != nil {
t.Fatal(err)
}
got := resp.Header.Get("Cache-Control")
testboil.FailTestIfDiff(t, got, want)
})
}

0 comments on commit b9036ca

Please sign in to comment.