github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/backend/s3/config_test.go (about) 1 package s3 2 3 import "testing" 4 5 var configTests = []struct { 6 s string 7 cfg Config 8 }{ 9 {"s3://eu-central-1/bucketname", Config{ 10 Endpoint: "eu-central-1", 11 Bucket: "bucketname", 12 Prefix: "", 13 Connections: 5, 14 }}, 15 {"s3://eu-central-1/bucketname/", Config{ 16 Endpoint: "eu-central-1", 17 Bucket: "bucketname", 18 Prefix: "", 19 Connections: 5, 20 }}, 21 {"s3://eu-central-1/bucketname/prefix/directory", Config{ 22 Endpoint: "eu-central-1", 23 Bucket: "bucketname", 24 Prefix: "prefix/directory", 25 Connections: 5, 26 }}, 27 {"s3://eu-central-1/bucketname/prefix/directory/", Config{ 28 Endpoint: "eu-central-1", 29 Bucket: "bucketname", 30 Prefix: "prefix/directory", 31 Connections: 5, 32 }}, 33 {"s3:eu-central-1/foobar", Config{ 34 Endpoint: "eu-central-1", 35 Bucket: "foobar", 36 Prefix: "", 37 Connections: 5, 38 }}, 39 {"s3:eu-central-1/foobar/", Config{ 40 Endpoint: "eu-central-1", 41 Bucket: "foobar", 42 Prefix: "", 43 Connections: 5, 44 }}, 45 {"s3:eu-central-1/foobar/prefix/directory", Config{ 46 Endpoint: "eu-central-1", 47 Bucket: "foobar", 48 Prefix: "prefix/directory", 49 Connections: 5, 50 }}, 51 {"s3:eu-central-1/foobar/prefix/directory/", Config{ 52 Endpoint: "eu-central-1", 53 Bucket: "foobar", 54 Prefix: "prefix/directory", 55 Connections: 5, 56 }}, 57 {"s3:https://hostname:9999/foobar", Config{ 58 Endpoint: "hostname:9999", 59 Bucket: "foobar", 60 Prefix: "", 61 Connections: 5, 62 }}, 63 {"s3:https://hostname:9999/foobar/", Config{ 64 Endpoint: "hostname:9999", 65 Bucket: "foobar", 66 Prefix: "", 67 Connections: 5, 68 }}, 69 {"s3:http://hostname:9999/foobar", Config{ 70 Endpoint: "hostname:9999", 71 Bucket: "foobar", 72 Prefix: "", 73 UseHTTP: true, 74 Connections: 5, 75 }}, 76 {"s3:http://hostname:9999/foobar/", Config{ 77 Endpoint: "hostname:9999", 78 Bucket: "foobar", 79 Prefix: "", 80 UseHTTP: true, 81 Connections: 5, 82 }}, 83 {"s3:http://hostname:9999/bucket/prefix/directory", Config{ 84 Endpoint: "hostname:9999", 85 Bucket: "bucket", 86 Prefix: "prefix/directory", 87 UseHTTP: true, 88 Connections: 5, 89 }}, 90 {"s3:http://hostname:9999/bucket/prefix/directory/", Config{ 91 Endpoint: "hostname:9999", 92 Bucket: "bucket", 93 Prefix: "prefix/directory", 94 UseHTTP: true, 95 Connections: 5, 96 }}, 97 } 98 99 func TestParseConfig(t *testing.T) { 100 for i, test := range configTests { 101 cfg, err := ParseConfig(test.s) 102 if err != nil { 103 t.Errorf("test %d:%s failed: %v", i, test.s, err) 104 continue 105 } 106 107 if cfg != test.cfg { 108 t.Errorf("test %d:\ninput:\n %s\n wrong config, want:\n %v\ngot:\n %v", 109 i, test.s, test.cfg, cfg) 110 continue 111 } 112 } 113 }