MCPcopy
hub / github.com/cli/cli / TestNewTrustedRootCmd

Function TestNewTrustedRootCmd

pkg/cmd/attestation/trustedroot/trustedroot_test.go:24–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestNewTrustedRootCmd(t *testing.T) {
25 testIO, _, _, _ := iostreams.Test()
26 f := &cmdutil.Factory{
27 IOStreams: testIO,
28 Config: func() (gh.Config, error) {
29 return &ghmock.ConfigMock{}, nil
30 },
31 HttpClient: func() (*http.Client, error) {
32 reg := &httpmock.Registry{}
33 client := &http.Client{}
34 httpmock.ReplaceTripper(client, reg)
35 return client, nil
36 },
37 ExternalHttpClient: func() (*http.Client, error) {
38 return nil, nil
39 },
40 }
41
42 testcases := []struct {
43 name string
44 cli string
45 wantsErr bool
46 }{
47 {
48 name: "Happy path",
49 cli: "",
50 wantsErr: false,
51 },
52 {
53 name: "Happy path",
54 cli: "--verify-only",
55 wantsErr: false,
56 },
57 {
58 name: "Custom TUF happy path",
59 cli: "--tuf-url https://tuf-repo.github.com --tuf-root ../verification/embed/tuf-repo.github.com/root.json",
60 wantsErr: false,
61 },
62 {
63 name: "Missing tuf-root flag",
64 cli: "--tuf-url https://tuf-repo.github.com",
65 wantsErr: true,
66 },
67 }
68
69 for _, tc := range testcases {
70 t.Run(tc.name, func(t *testing.T) {
71 cmd := NewTrustedRootCmd(f, func(_ *Options) error {
72 return nil
73 })
74
75 argv := []string{}
76 if tc.cli != "" {
77 argv = strings.Split(tc.cli, " ")
78 }
79 cmd.SetArgs(argv)
80 cmd.SetIn(&bytes.Buffer{})
81 cmd.SetOut(&bytes.Buffer{})

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
ReplaceTripperFunction · 0.92
NewTrustedRootCmdFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected