MCPcopy
hub / github.com/cli/cli / TestGetTrustedRoot

Function TestGetTrustedRoot

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

Source from the content-addressed store, hash-verified

179}
180
181func TestGetTrustedRoot(t *testing.T) {
182 mirror := "https://tuf-repo.github.com"
183 root := test.NormalizeRelativePath("../verification/embed/tuf-repo.github.com/root.json")
184
185 opts := &Options{
186 TufUrl: mirror,
187 TufRootPath: root,
188 }
189
190 reg := &httpmock.Registry{}
191 client := &http.Client{}
192 httpmock.ReplaceTripper(client, reg)
193
194 t.Run("failed to create TUF root", func(t *testing.T) {
195 err := getTrustedRoot(newTUFErrClient, opts, client)
196 require.Error(t, err)
197 require.ErrorContains(t, err, "failed to create TUF client")
198 })
199
200 t.Run("fails because the root cannot be found", func(t *testing.T) {
201 opts.TufRootPath = test.NormalizeRelativePath("./does/not/exist/root.json")
202 err := getTrustedRoot(tuf.New, opts, client)
203 require.Error(t, err)
204 require.ErrorContains(t, err, "failed to read root file")
205 })
206
207}
208
209type stubAuthConfig struct {
210 config.AuthConfig

Callers

nothing calls this directly

Calls 5

NormalizeRelativePathFunction · 0.92
ReplaceTripperFunction · 0.92
getTrustedRootFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected