-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_test.go
More file actions
36 lines (32 loc) · 825 Bytes
/
common_test.go
File metadata and controls
36 lines (32 loc) · 825 Bytes
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
package flashduty
import (
"context"
"encoding/json"
"net/http"
"testing"
)
func TestGetDataDecodesEnvelope(t *testing.T) {
client := newSDKExtensionsTestClient(t, func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Fatalf("method = %s, want GET", r.Method)
}
if r.URL.Path != "/common/test" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"data": map[string]any{
"name": "ok",
},
})
})
out, err := getData[struct {
Name string `json:"name"`
}](client, context.Background(), "/common/test", "failed to get test data")
if err != nil {
t.Fatalf("getData returned error: %v", err)
}
if out.Name != "ok" {
t.Fatalf("name = %q, want ok", out.Name)
}
}