mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestOneStrings(t *testing.T) {
|
|
out, err := json.Marshal(Strings{"one"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
|
|
}
|
|
expected := "\"one\""
|
|
if string(out) != expected {
|
|
t.Fatalf("expected %s, got %s", expected, string(out))
|
|
}
|
|
}
|
|
|
|
func TestNoStrings(t *testing.T) {
|
|
out, err := json.Marshal(Strings{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
|
|
}
|
|
expected := "null"
|
|
if string(out) != expected {
|
|
t.Fatalf("expected %s, got %s", expected, string(out))
|
|
}
|
|
}
|
|
|
|
func TestManyStrings(t *testing.T) {
|
|
out, err := json.Marshal(Strings{"one", "two"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
|
|
}
|
|
expected := "[\"one\",\"two\"]"
|
|
if string(out) != expected {
|
|
t.Fatalf("expected %s, got %s", expected, string(out))
|
|
}
|
|
}
|
|
|
|
func TestFunkyStrings(t *testing.T) {
|
|
toParse := " [ \"one\", \"two\" ] "
|
|
var s Strings
|
|
if err := json.Unmarshal([]byte(toParse), &s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(s) != 2 || s[0] != "one" && s[1] != "two" {
|
|
t.Fatalf("unexpected result: %v", s)
|
|
}
|
|
}
|