-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: docker exec to in memory registry (#2869)
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
- Loading branch information
1 parent
aa4c438
commit 9f7b178
Showing
9 changed files
with
98 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package testutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"testing" | ||
"time" | ||
|
||
"github.com/distribution/distribution/v3/configuration" | ||
"github.com/distribution/distribution/v3/registry" | ||
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" // used for docker test registry | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// SetupInMemoryRegistry sets up an in-memory registry on localhost and returns the address. | ||
func SetupInMemoryRegistry(ctx context.Context, t *testing.T, port int) string { | ||
t.Helper() | ||
config := &configuration.Configuration{} | ||
config.HTTP.Addr = fmt.Sprintf(":%d", port) | ||
config.Log.AccessLog.Disabled = true | ||
config.Log.Level = "error" | ||
logrus.SetOutput(io.Discard) | ||
config.HTTP.DrainTimeout = 10 * time.Second | ||
config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}} | ||
ref, err := registry.NewRegistry(ctx, config) | ||
require.NoError(t, err) | ||
//nolint:errcheck // ignore | ||
go ref.ListenAndServe() | ||
return fmt.Sprintf("localhost:%d", port) | ||
} |