...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package tests
17
18 import (
19 "net/http"
20 "net/http/httptest"
21 "testing"
22 "time"
23
24 "github.com/spf13/viper"
25
26 "github.com/sigstore/timestamp-authority/pkg/server"
27 )
28
29 func createServer(t *testing.T) string {
30 viper.Set("timestamp-signer", "memory")
31 viper.Set("timestamp-signer-hash", "sha256")
32
33 apiServer := server.NewRestAPIServer("localhost", 0, []string{"http"}, false, 10*time.Second, 10*time.Second)
34 server := httptest.NewServer(apiServer.GetHandler())
35 t.Cleanup(server.Close)
36
37
38 response, err := http.Get(server.URL + "/ping")
39 if err != nil || response.StatusCode != 200 {
40 t.Fatalf("unexpected error starting up server - status code: %d, err: %v", response.StatusCode, err)
41 }
42
43 return server.URL
44 }
45
View as plain text