-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
34 lines (28 loc) · 648 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/shoenig/test/must"
)
func TestRun(t *testing.T) {
t.Setenv("BIND", "127.0.0.1")
t.Setenv("PORT", "8787")
dir, err := os.MkdirTemp("", "")
must.NoError(t, err)
filename := filepath.Join(dir, "hi.txt")
err = os.WriteFile(filename, []byte("hello"), 0o644)
must.NoError(t, err)
t.Log("dir", dir)
args := []string{"just-files", "/:" + dir}
go func() {
err := run(args)
must.NoError(t, err)
}()
time.Sleep(500 * time.Millisecond)
resp, err := http.Get("http://127.0.0.1:8787/hi.txt")
must.NoError(t, err)
must.Eq(t, 200, resp.StatusCode)
}