(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestParseConsulURL(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | in string |
| 14 | config *api.Config |
| 15 | key string |
| 16 | errstr string |
| 17 | }{ |
| 18 | { |
| 19 | name: "empty url", |
| 20 | errstr: "invalid url", |
| 21 | }, |
| 22 | { |
| 23 | name: "invalid url", |
| 24 | in: "this is not a url", |
| 25 | errstr: "invalid url", |
| 26 | }, |
| 27 | { |
| 28 | name: "no kv store url", |
| 29 | in: "http://localhost:8500/path/to/cert", |
| 30 | errstr: "missing prefix: /v1/kv/", |
| 31 | }, |
| 32 | { |
| 33 | name: "url without token", |
| 34 | in: "http://localhost:8500/v1/kv/path/to/cert", |
| 35 | config: &api.Config{Address: "localhost:8500", Scheme: "http"}, |
| 36 | key: "path/to/cert", |
| 37 | }, |
| 38 | { |
| 39 | name: "https url", |
| 40 | in: "https://localhost:8500/v1/kv/path/to/cert", |
| 41 | config: &api.Config{Address: "localhost:8500", Scheme: "https"}, |
| 42 | key: "path/to/cert", |
| 43 | }, |
| 44 | { |
| 45 | name: "url with token", |
| 46 | in: "http://localhost:8500/v1/kv/path/to/cert?token=123", |
| 47 | config: &api.Config{Address: "localhost:8500", Scheme: "http", Token: "123"}, |
| 48 | key: "path/to/cert", |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | for _, tt := range tests { |
| 53 | t.Run(tt.name, func(t *testing.T) { |
| 54 | config, key, err := parseConsulURL(tt.in) |
| 55 | var errstr string |
| 56 | if err != nil { |
| 57 | errstr = err.Error() |
| 58 | } |
| 59 | if got, want := errstr, tt.errstr; got != want { |
| 60 | t.Fatalf("got err %q want %q", got, want) |
| 61 | } |
| 62 | if errstr != "" || tt.errstr != "" { |
| 63 | return |
| 64 | } |
| 65 | if got, want := key, tt.key; got != want { |
| 66 | t.Errorf("got key %q want %q", got, want) |
| 67 | } |
nothing calls this directly
no test coverage detected