New starts a new Docker registry listening on localhost. It will automatically shut down when the test finishes. It will store data in memory.
(t testing.TB, mws ...func(http.Handler) http.Handler)
| 33 | // It will automatically shut down when the test finishes. |
| 34 | // It will store data in memory. |
| 35 | func New(t testing.TB, mws ...func(http.Handler) http.Handler) string { |
| 36 | t.Helper() |
| 37 | regHandler := registry.New(registry.WithBlobHandler(registry.NewInMemoryBlobHandler())) |
| 38 | for _, mw := range mws { |
| 39 | regHandler = mw(regHandler) |
| 40 | } |
| 41 | regSrv := httptest.NewServer(regHandler) |
| 42 | t.Cleanup(func() { regSrv.Close() }) |
| 43 | regSrvURL, err := url.Parse(regSrv.URL) |
| 44 | require.NoError(t, err) |
| 45 | return fmt.Sprintf("localhost:%s", regSrvURL.Port()) |
| 46 | } |
| 47 | |
| 48 | // WriteContainer uploads a container to the registry server. |
| 49 | // It returns the reference to the uploaded container. |