github.com/mckael/restic@v0.8.3/internal/backend/swift/config_test.go (about) 1 package swift 2 3 import "testing" 4 5 var configTests = []struct { 6 s string 7 cfg Config 8 }{ 9 { 10 "swift:cnt1:/", 11 Config{ 12 Container: "cnt1", 13 Prefix: "", 14 Connections: 5, 15 }, 16 }, 17 { 18 "swift:cnt2:/prefix", 19 Config{Container: "cnt2", 20 Prefix: "prefix", 21 Connections: 5, 22 }, 23 }, 24 { 25 "swift:cnt3:/prefix/longer", 26 Config{Container: "cnt3", 27 Prefix: "prefix/longer", 28 Connections: 5, 29 }, 30 }, 31 } 32 33 func TestParseConfig(t *testing.T) { 34 for _, test := range configTests { 35 t.Run("", func(t *testing.T) { 36 v, err := ParseConfig(test.s) 37 if err != nil { 38 t.Fatalf("parsing %q failed: %v", test.s, err) 39 } 40 41 cfg, ok := v.(Config) 42 if !ok { 43 t.Fatalf("wrong type returned, want Config, got %T", cfg) 44 } 45 46 if cfg != test.cfg { 47 t.Fatalf("wrong output for %q, want:\n %#v\ngot:\n %#v", 48 test.s, test.cfg, cfg) 49 } 50 }) 51 } 52 } 53 54 var configTestsInvalid = []string{ 55 "swift://hostname/container", 56 "swift:////", 57 "swift://", 58 "swift:////prefix", 59 "swift:container", 60 "swift:container:", 61 "swift:container/prefix", 62 } 63 64 func TestParseConfigInvalid(t *testing.T) { 65 for i, test := range configTestsInvalid { 66 _, err := ParseConfig(test) 67 if err == nil { 68 t.Errorf("test %d: invalid config %s did not return an error", i, test) 69 continue 70 } 71 } 72 }