go-ipfs-config: add tests for the "Strings" type
(missed in my previous PR)
Steven Allen committed
Oct 23, 2018 at 09:49 UTC
3cd45d889ab0326cbafd6b36c17aa9d81991cea7
1 file changed
+53
config/types_test.go
new
+53
@@ -0,0 +1,53 @@
1
+package config
2
+
3
+import (
4
+ "encoding/json"
5
+ "testing"
6
+)
7
+
8
+func TestOneStrings(t *testing.T) {
9
+ out, err := json.Marshal(Strings{"one"})
10
+ if err != nil {
11
+ t.Fatal(err)
12
+
13
+ }
14
+ expected := "\"one\""
15
+ if string(out) != expected {
16
+ t.Fatalf("expected %s, got %s", expected, string(out))
17
+ }
18
+}
19
+
20
+func TestNoStrings(t *testing.T) {
21
+ out, err := json.Marshal(Strings{})
22
+ if err != nil {
23
+ t.Fatal(err)
24
+
25
+ }
26
+ expected := "null"
27
+ if string(out) != expected {
28
+ t.Fatalf("expected %s, got %s", expected, string(out))
29
+ }
30
+}
31
+
32
+func TestManyStrings(t *testing.T) {
33
+ out, err := json.Marshal(Strings{"one", "two"})
34
+ if err != nil {
35
+ t.Fatal(err)
36
+
37
+ }
38
+ expected := "[\"one\",\"two\"]"
39
+ if string(out) != expected {
40
+ t.Fatalf("expected %s, got %s", expected, string(out))
41
+ }
42
+}
43
+
44
+func TestFunkyStrings(t *testing.T) {
45
+ toParse := " [ \"one\", \"two\" ] "
46
+ var s Strings
47
+ if err := json.Unmarshal([]byte(toParse), &s); err != nil {
48
+ t.Fatal(err)
49
+ }
50
+ if len(s) != 2 || s[0] != "one" && s[1] != "two" {
51
+ t.Fatalf("unexpected result: %v", s)
52
+ }
53
+}