This repository was archived by the owner on Jan 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwarm_test.go
More file actions
68 lines (62 loc) · 1.66 KB
/
warm_test.go
File metadata and controls
68 lines (62 loc) · 1.66 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tpuf_test
import (
"bytes"
"context"
"io"
"net/http"
"testing"
"github.com/bamo/tpuf-go"
"github.com/stretchr/testify/assert"
)
func TestWarmCache(t *testing.T) {
tests := []struct {
name string
namespace string
httpResponse *http.Response
httpError error
expectedError string
expectedMethod string
expectedURL string
expectedResult *tpuf.WarmCacheResult
}{
{
name: "successful warm cache",
namespace: "test-namespace",
httpResponse: &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(`{
"status": "ACCEPTED",
"message": "cache starting to warm"
}`)),
},
expectedMethod: http.MethodGet,
expectedURL: "https://api.turbopuffer.com/v1/namespaces/test-namespace/hint_cache_warm",
expectedResult: &tpuf.WarmCacheResult{
Status: "ACCEPTED",
Message: "cache starting to warm",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := &tpuf.Client{
ApiToken: "test-token",
HttpClient: &fakeHttpClient{
doFunc: func(req *http.Request) (*http.Response, error) {
assert.Equal(t, tt.expectedMethod, req.Method, "unexpected request method")
assert.Equal(t, tt.expectedURL, req.URL.String(), "unexpected request URL")
return tt.httpResponse, tt.httpError
},
},
}
result, err := client.WarmCache(context.Background(), tt.namespace)
if tt.expectedError == "" {
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, result, "unexpected warm cache result")
} else {
assert.EqualError(t, err, tt.expectedError)
assert.Nil(t, result)
}
})
}
}