(t *testing.T)
| 46 | } |
| 47 | |
| 48 | func TestParseCaURLIfExists(t *testing.T) { |
| 49 | // This is just to get a simple CLI context |
| 50 | app := &cli.App{} |
| 51 | set := flag.NewFlagSet("contrive", 0) |
| 52 | _ = set.String("ca-url", "", "") |
| 53 | ctx := cli.NewContext(app, set, nil) |
| 54 | |
| 55 | type test struct { |
| 56 | name, caURL, ret string |
| 57 | err error |
| 58 | } |
| 59 | tests := []test{ |
| 60 | {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")}, |
| 61 | {name: "ok/empty", caURL: "", ret: ""}, |
| 62 | {name: "ok", caURL: "https://ca.smallstep.com:8080", ret: "https://ca.smallstep.com:8080"}, |
| 63 | } |
| 64 | for _, tc := range tests { |
| 65 | t.Run(tc.name, func(t *testing.T) { |
| 66 | ctx.Set("ca-url", tc.caURL) |
| 67 | ret, err := ParseCaURLIfExists(ctx) |
| 68 | if err != nil && assert.NotNil(t, tc.err, fmt.Sprintf("expected no error but got <%s>", err)) { |
| 69 | assert.HasPrefix(t, err.Error(), tc.err.Error()) |
| 70 | } else if assert.Nil(t, tc.err, fmt.Sprintf("expected error <%s> but got nil", tc.err)) { |
| 71 | assert.Equals(t, ret, tc.ret) |
| 72 | } |
| 73 | }) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func Test_parseCaURL(t *testing.T) { |
| 78 | // This is just to get a simple CLI context |
nothing calls this directly
no test coverage detected
searching dependent graphs…