MCPcopy
hub / github.com/smallstep/cli / TestParseCaURL

Function TestParseCaURL

flags/flags_test.go:19–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func 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
48func TestParseCaURLIfExists(t *testing.T) {
49 // This is just to get a simple CLI context

Callers

nothing calls this directly

Calls 5

ParseCaURLFunction · 0.85
SetMethod · 0.80
StringMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…