MCPcopy
hub / github.com/moby/moby / TestImagePushWithPrivilegedFuncNoError

Function TestImagePushWithPrivilegedFuncNoError

client/image_push_test.go:68–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestImagePushWithPrivilegedFuncNoError(t *testing.T) {
69 const expectedURL = "/images/docker.io/myname/myimage/push"
70 const invalidAuth = "NotValid"
71 const validAuth = "IAmValid"
72 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
73 if err := assertRequest(req, http.MethodPost, expectedURL); err != nil {
74 return nil, err
75 }
76 auth := req.Header.Get(registry.AuthHeader)
77 if auth == invalidAuth {
78 return mockResponse(http.StatusUnauthorized, nil, "Invalid credentials")(req)
79 }
80 if auth != validAuth {
81 return nil, fmt.Errorf("invalid auth header: expected %s, got %s", "IAmValid", auth)
82 }
83 query := req.URL.Query()
84 tag := query.Get("tag")
85 if tag != "tag" {
86 return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", "tag", tag)
87 }
88 return mockResponse(http.StatusOK, nil, "hello world")(req)
89 }))
90 assert.NilError(t, err)
91 resp, err := client.ImagePush(t.Context(), "myname/myimage:tag", ImagePushOptions{
92 RegistryAuth: invalidAuth,
93 PrivilegeFunc: staticAuth(validAuth),
94 })
95 assert.NilError(t, err)
96 body, err := io.ReadAll(resp)
97 assert.NilError(t, err)
98 assert.Check(t, is.Equal(string(body), "hello world"))
99}
100
101func TestImagePushWithoutErrors(t *testing.T) {
102 const (

Callers

nothing calls this directly

Calls 11

WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockResponseFunction · 0.85
staticAuthFunction · 0.85
ErrorfMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
ImagePushMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…