(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func 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 | |
| 101 | func TestImagePushWithoutErrors(t *testing.T) { |
| 102 | const ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…