(t *testing.T, ctx context.Context)
| 1072 | } |
| 1073 | |
| 1074 | func startLocalRegistry(t *testing.T, ctx context.Context) string { |
| 1075 | t.Helper() |
| 1076 | c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) |
| 1077 | require.NoError(t, err) |
| 1078 | defer c.Close() |
| 1079 | |
| 1080 | reader, err := c.ImagePull(ctx, "registry:2", image.PullOptions{}) |
| 1081 | require.NoError(t, err) |
| 1082 | io.Copy(io.Discard, reader) |
| 1083 | reader.Close() |
| 1084 | |
| 1085 | port := getFreePort(t) |
| 1086 | portStr := strconv.Itoa(port) |
| 1087 | |
| 1088 | resp, err := c.ContainerCreate(ctx, |
| 1089 | &container.Config{Image: "registry:2"}, |
| 1090 | &container.HostConfig{ |
| 1091 | PortBindings: nat.PortMap{ |
| 1092 | "5000/tcp": []nat.PortBinding{{HostPort: portStr}}, |
| 1093 | }, |
| 1094 | }, |
| 1095 | nil, nil, fmt.Sprintf("test-registry-%s", portStr), |
| 1096 | ) |
| 1097 | require.NoError(t, err) |
| 1098 | t.Cleanup(func() { |
| 1099 | c.ContainerRemove(context.Background(), resp.ID, container.RemoveOptions{Force: true}) |
| 1100 | }) |
| 1101 | |
| 1102 | require.NoError(t, c.ContainerStart(ctx, resp.ID, container.StartOptions{})) |
| 1103 | |
| 1104 | registryURL := fmt.Sprintf("localhost:%d", port) |
| 1105 | require.Eventually(t, func() bool { |
| 1106 | resp, err := http.Get("http://" + registryURL + "/v2/") |
| 1107 | if err != nil { |
| 1108 | return false |
| 1109 | } |
| 1110 | resp.Body.Close() |
| 1111 | return resp.StatusCode == http.StatusOK |
| 1112 | }, 10*time.Second, 200*time.Millisecond, "registry did not become ready") |
| 1113 | |
| 1114 | return registryURL |
| 1115 | } |
| 1116 | |
| 1117 | func buildHookImage(t *testing.T, ctx context.Context, registryURL, name, hookScript string) string { |
| 1118 | t.Helper() |
no test coverage detected
searching dependent graphs…