master
go 34 lines 659 Bytes
Raw
1 package config
2
3 import (
4 "encoding/json"
5 "testing"
6 )
7
8 func TestMigrationDecode(t *testing.T) {
9 str := `
10 {
11 "DownloadSources": ["IPFS", "HTTP", "127.0.0.1"],
12 "Keep": "cache"
13 }
14 `
15
16 var cfg Migration
17 if err := json.Unmarshal([]byte(str), &cfg); err != nil {
18 t.Errorf("failed while unmarshalling migration struct: %s", err)
19 }
20
21 if len(cfg.DownloadSources) != 3 {
22 t.Fatal("wrong number of DownloadSources")
23 }
24 expect := []string{"IPFS", "HTTP", "127.0.0.1"}
25 for i := range expect {
26 if cfg.DownloadSources[i] != expect[i] {
27 t.Errorf("wrong DownloadSource at %d", i)
28 }
29 }
30
31 if cfg.Keep != "cache" {
32 t.Error("wrong value for Keep")
33 }
34 }