forked from wit-ai/wit-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamples_test.go
62 lines (51 loc) · 1.41 KB
/
samples_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
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
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
package witai
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestGetSamples(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte(`[{"text": "s1"}, {"text":"s2"}]`))
}))
defer func() { testServer.Close() }()
c := NewClient(unitTestToken)
c.APIBase = testServer.URL
samples, _ := c.GetSamples(1, 0)
if len(samples) != 2 {
t.Fatalf("expected 2 samples, got: %v", samples)
}
}
func TestValidateSamples(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte(`{"sent": true, "n": 2}`))
}))
defer func() { testServer.Close() }()
c := NewClient(unitTestToken)
c.APIBase = testServer.URL
r, _ := c.ValidateSamples([]Sample{
{
Text: "hello",
},
})
if r.N != 2 || !r.Sent {
t.Fatalf("expected N=2 and Sent=true, got: %v", r)
}
}
func TestDeleteSamples(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte(`{"sent": true, "n": 2}`))
}))
defer func() { testServer.Close() }()
c := NewClient(unitTestToken)
c.APIBase = testServer.URL
r, _ := c.DeleteSamples([]Sample{
{
Text: "hello",
},
})
if r.N != 2 || !r.Sent {
t.Fatalf("expected N=2 and Sent=true, got: %v", r)
}
}