-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpinata_test.go
61 lines (56 loc) · 1.25 KB
/
pinata_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
package pinata
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestAuthentication(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "")
}))
defer ts.Close()
client := NewClient("", "")
client.BaseURL = ts.URL
_, err := client.TestAuthentication()
if err != nil {
t.Error(err)
}
}
func TestMetadata(t *testing.T) {
m := NewMetadata()
if m.Name != "" {
t.Error("Metadata.Name should be an empty string")
}
m = NewMetadataWithName("bob")
if m.Name != "bob" {
t.Error("Metadata.Name should equal 'bob'")
}
tests := []struct {
Key string
Value interface{}
ShouldError bool
}{
{"test_string", "", false},
{"test_int", int(5), false},
{"test_int64", int64(5), false},
{"test_float32", float32(5.001), false},
{"test_float64", float64(5.001), false},
{"test_time", time.Now(), false},
{"test_bytes", []byte("no good"), true},
{"test_bool", true, true},
}
for _, test := range tests {
err := m.SetKeyValue(test.Key, test.Value)
if test.ShouldError {
if err == nil {
t.Errorf("%v : %v should have returned an error, but did not", test.Key, test.Value)
}
} else {
if err != nil {
t.Error(err)
}
}
}
}