(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestParseCaURL(t *testing.T) { |
| 20 | // This is just to get a simple CLI context |
| 21 | app := &cli.App{} |
| 22 | set := flag.NewFlagSet("contrive", 0) |
| 23 | _ = set.String("ca-url", "", "") |
| 24 | ctx := cli.NewContext(app, set, nil) |
| 25 | |
| 26 | type test struct { |
| 27 | name, caURL, ret string |
| 28 | err error |
| 29 | } |
| 30 | tests := []test{ |
| 31 | {name: "fail/empty", caURL: "", ret: "", err: errors.New("' ' requires the '--ca-url' flag")}, |
| 32 | {name: "fail/badCaURL", caURL: "git://git@github.com", ret: "", err: errors.New("invalid value 'git://git@github.com' for flag '--ca-url'; must have https scheme")}, |
| 33 | {name: "ok", caURL: "https://ca.smallstep.com:8080", ret: "https://ca.smallstep.com:8080"}, |
| 34 | } |
| 35 | for _, tc := range tests { |
| 36 | t.Run(tc.name, func(t *testing.T) { |
| 37 | ctx.Set("ca-url", tc.caURL) |
| 38 | ret, err := ParseCaURL(ctx) |
| 39 | if err != nil && assert.NotNil(t, tc.err, fmt.Sprintf("expected no error but got <%s>", err)) { |
| 40 | assert.HasPrefix(t, err.Error(), tc.err.Error()) |
| 41 | } else if assert.Nil(t, tc.err, fmt.Sprintf("expected error <%s> but got nil", tc.err)) { |
| 42 | assert.Equals(t, ret, tc.ret) |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestParseCaURLIfExists(t *testing.T) { |
| 49 | // This is just to get a simple CLI context |
nothing calls this directly
no test coverage detected
searching dependent graphs…