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

Function TestParseCaURLIfExists

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

Source from the content-addressed store, hash-verified

46}
47
48func 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
77func Test_parseCaURL(t *testing.T) {
78 // This is just to get a simple CLI context

Callers

nothing calls this directly

Calls 5

ParseCaURLIfExistsFunction · 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…