-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_test.go
56 lines (43 loc) · 1.19 KB
/
integration_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
// +build integration
package jsonstore
import (
"context"
"testing"
)
func TestIntegration(t *testing.T) {
ctx := context.Background()
key := "test"
// Create a new client with a random secret
c := New()
// Post some data to jsonstore.io
if err := c.Post(ctx, key, testData{Foo: 123, Bar: false, Baz: "abc"}); err != nil {
t.Fatalf("c.Post for %s returned error: %v", c.URL(key), err)
}
// Modify the Baz value
if err := c.Put(ctx, key+"/Baz", "cde"); err != nil {
t.Fatalf("c.Put for %s returned error: %v", c.URL(key+"/Baz"), err)
}
var td testData
// Retrieve the test data from the key
if err := c.Get(ctx, key, &td); err != nil {
t.Fatalf("c.Get for %s returned error: %v", c.URL(key), err)
}
if got, want := td.Foo, 123; got != want {
t.Fatalf("td.Foo = %d, want %d", got, want)
}
if got, want := td.Bar, false; got != want {
t.Fatalf("td.Bar = %v, want %v", got, want)
}
if got, want := td.Baz, "cde"; got != want {
t.Fatalf("td.Baz = %q, want %q", got, want)
}
// Delete all of the data
if err := c.Delete(ctx, key); err != nil {
t.Fatalf("c.Delete for %s returned error: %v", c.URL(key), err)
}
}
type testData struct {
Foo int
Bar bool
Baz string
}