Add shutdown to test environment
Ensures test http server is fully closed before moving on with test. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
38ee36eee4
commit
798b7331ca
2 changed files with 38 additions and 12 deletions
|
@ -43,6 +43,7 @@ var headerConfig = http.Header{
|
|||
// 200 OK response.
|
||||
func TestCheckAPI(t *testing.T) {
|
||||
env := newTestEnv(t, false)
|
||||
defer env.Shutdown()
|
||||
baseURL, err := env.builder.BuildBaseURL()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error building base url: %v", err)
|
||||
|
@ -74,6 +75,7 @@ func TestCheckAPI(t *testing.T) {
|
|||
func TestCatalogAPI(t *testing.T) {
|
||||
chunkLen := 2
|
||||
env := newTestEnv(t, false)
|
||||
defer env.Shutdown()
|
||||
|
||||
values := url.Values{
|
||||
"last": []string{""},
|
||||
|
@ -229,6 +231,7 @@ func TestURLPrefix(t *testing.T) {
|
|||
config.HTTP.Headers = headerConfig
|
||||
|
||||
env := newTestEnvWithConfig(t, &config)
|
||||
defer env.Shutdown()
|
||||
|
||||
baseURL, err := env.builder.BuildBaseURL()
|
||||
if err != nil {
|
||||
|
@ -276,20 +279,23 @@ func makeBlobArgs(t *testing.T) blobArgs {
|
|||
// TestBlobAPI conducts a full test of the of the blob api.
|
||||
func TestBlobAPI(t *testing.T) {
|
||||
deleteEnabled := false
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
env1 := newTestEnv(t, deleteEnabled)
|
||||
defer env1.Shutdown()
|
||||
args := makeBlobArgs(t)
|
||||
testBlobAPI(t, env, args)
|
||||
testBlobAPI(t, env1, args)
|
||||
|
||||
deleteEnabled = true
|
||||
env = newTestEnv(t, deleteEnabled)
|
||||
env2 := newTestEnv(t, deleteEnabled)
|
||||
defer env2.Shutdown()
|
||||
args = makeBlobArgs(t)
|
||||
testBlobAPI(t, env, args)
|
||||
testBlobAPI(t, env2, args)
|
||||
|
||||
}
|
||||
|
||||
func TestBlobDelete(t *testing.T) {
|
||||
deleteEnabled := true
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
defer env.Shutdown()
|
||||
|
||||
args := makeBlobArgs(t)
|
||||
env = testBlobAPI(t, env, args)
|
||||
|
@ -308,6 +314,7 @@ func TestRelativeURL(t *testing.T) {
|
|||
config.HTTP.Headers = headerConfig
|
||||
config.HTTP.RelativeURLs = false
|
||||
env := newTestEnvWithConfig(t, &config)
|
||||
defer env.Shutdown()
|
||||
ref, _ := reference.WithName("foo/bar")
|
||||
uploadURLBaseAbs, _ := startPushLayer(t, env, ref)
|
||||
|
||||
|
@ -375,6 +382,7 @@ func TestRelativeURL(t *testing.T) {
|
|||
func TestBlobDeleteDisabled(t *testing.T) {
|
||||
deleteEnabled := false
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
defer env.Shutdown()
|
||||
args := makeBlobArgs(t)
|
||||
|
||||
imageName := args.imageName
|
||||
|
@ -690,6 +698,7 @@ func testBlobDelete(t *testing.T, env *testEnv, args blobArgs) {
|
|||
|
||||
func TestDeleteDisabled(t *testing.T) {
|
||||
env := newTestEnv(t, false)
|
||||
defer env.Shutdown()
|
||||
|
||||
imageName, _ := reference.ParseNamed("foo/bar")
|
||||
// "build" our layer file
|
||||
|
@ -716,6 +725,7 @@ func TestDeleteDisabled(t *testing.T) {
|
|||
|
||||
func TestDeleteReadOnly(t *testing.T) {
|
||||
env := newTestEnv(t, true)
|
||||
defer env.Shutdown()
|
||||
|
||||
imageName, _ := reference.ParseNamed("foo/bar")
|
||||
// "build" our layer file
|
||||
|
@ -744,6 +754,7 @@ func TestDeleteReadOnly(t *testing.T) {
|
|||
|
||||
func TestStartPushReadOnly(t *testing.T) {
|
||||
env := newTestEnv(t, true)
|
||||
defer env.Shutdown()
|
||||
env.app.readOnly = true
|
||||
|
||||
imageName, _ := reference.ParseNamed("foo/bar")
|
||||
|
@ -788,16 +799,18 @@ func TestManifestAPI(t *testing.T) {
|
|||
schema2Repo, _ := reference.ParseNamed("foo/schema2")
|
||||
|
||||
deleteEnabled := false
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
testManifestAPISchema1(t, env, schema1Repo)
|
||||
schema2Args := testManifestAPISchema2(t, env, schema2Repo)
|
||||
testManifestAPIManifestList(t, env, schema2Args)
|
||||
env1 := newTestEnv(t, deleteEnabled)
|
||||
defer env1.Shutdown()
|
||||
testManifestAPISchema1(t, env1, schema1Repo)
|
||||
schema2Args := testManifestAPISchema2(t, env1, schema2Repo)
|
||||
testManifestAPIManifestList(t, env1, schema2Args)
|
||||
|
||||
deleteEnabled = true
|
||||
env = newTestEnv(t, deleteEnabled)
|
||||
testManifestAPISchema1(t, env, schema1Repo)
|
||||
schema2Args = testManifestAPISchema2(t, env, schema2Repo)
|
||||
testManifestAPIManifestList(t, env, schema2Args)
|
||||
env2 := newTestEnv(t, deleteEnabled)
|
||||
defer env2.Shutdown()
|
||||
testManifestAPISchema1(t, env2, schema1Repo)
|
||||
schema2Args = testManifestAPISchema2(t, env2, schema2Repo)
|
||||
testManifestAPIManifestList(t, env2, schema2Args)
|
||||
}
|
||||
|
||||
func TestManifestDelete(t *testing.T) {
|
||||
|
@ -806,6 +819,7 @@ func TestManifestDelete(t *testing.T) {
|
|||
|
||||
deleteEnabled := true
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
defer env.Shutdown()
|
||||
schema1Args := testManifestAPISchema1(t, env, schema1Repo)
|
||||
testManifestDelete(t, env, schema1Args)
|
||||
schema2Args := testManifestAPISchema2(t, env, schema2Repo)
|
||||
|
@ -816,6 +830,7 @@ func TestManifestDeleteDisabled(t *testing.T) {
|
|||
schema1Repo, _ := reference.ParseNamed("foo/schema1")
|
||||
deleteEnabled := false
|
||||
env := newTestEnv(t, deleteEnabled)
|
||||
defer env.Shutdown()
|
||||
testManifestDeleteDisabled(t, env, schema1Repo)
|
||||
}
|
||||
|
||||
|
@ -1947,6 +1962,11 @@ func newTestEnvWithConfig(t *testing.T, config *configuration.Configuration) *te
|
|||
}
|
||||
}
|
||||
|
||||
func (t *testEnv) Shutdown() {
|
||||
t.server.CloseClientConnections()
|
||||
t.server.Close()
|
||||
}
|
||||
|
||||
func putManifest(t *testing.T, msg, url, contentType string, v interface{}) *http.Response {
|
||||
var body []byte
|
||||
|
||||
|
@ -2340,6 +2360,7 @@ func createRepository(env *testEnv, t *testing.T, imageName string, tag string)
|
|||
func TestRegistryAsCacheMutationAPIs(t *testing.T) {
|
||||
deleteEnabled := true
|
||||
env := newTestEnvMirror(t, deleteEnabled)
|
||||
defer env.Shutdown()
|
||||
|
||||
imageName, _ := reference.ParseNamed("foo/bar")
|
||||
tag := "latest"
|
||||
|
@ -2398,6 +2419,7 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {
|
|||
// that implements http.ContextNotifier.
|
||||
func TestCheckContextNotifier(t *testing.T) {
|
||||
env := newTestEnv(t, false)
|
||||
defer env.Shutdown()
|
||||
|
||||
// Register a new endpoint for testing
|
||||
env.app.router.Handle("/unittest/{name}/", env.app.dispatcher(func(ctx *Context, r *http.Request) http.Handler {
|
||||
|
@ -2437,6 +2459,7 @@ func TestProxyManifestGetByTag(t *testing.T) {
|
|||
tag := "latest"
|
||||
|
||||
truthEnv := newTestEnvWithConfig(t, &truthConfig)
|
||||
defer truthEnv.Shutdown()
|
||||
// create a repository in the truth registry
|
||||
dgst := createRepository(truthEnv, t, imageName.Name(), tag)
|
||||
|
||||
|
@ -2451,6 +2474,7 @@ func TestProxyManifestGetByTag(t *testing.T) {
|
|||
proxyConfig.HTTP.Headers = headerConfig
|
||||
|
||||
proxyEnv := newTestEnvWithConfig(t, &proxyConfig)
|
||||
defer proxyEnv.Shutdown()
|
||||
|
||||
digestRef, _ := reference.WithDigest(imageName, dgst)
|
||||
manifestDigestURL, err := proxyEnv.builder.BuildManifestURL(digestRef)
|
||||
|
|
|
@ -38,6 +38,7 @@ func TestAppDispatcher(t *testing.T) {
|
|||
registry: registry,
|
||||
}
|
||||
server := httptest.NewServer(app)
|
||||
defer server.Close()
|
||||
router := v2.Router()
|
||||
|
||||
serverURL, err := url.Parse(server.URL)
|
||||
|
@ -163,6 +164,7 @@ func TestNewApp(t *testing.T) {
|
|||
app := NewApp(ctx, &config)
|
||||
|
||||
server := httptest.NewServer(app)
|
||||
defer server.Close()
|
||||
builder, err := v2.NewURLBuilderFromString(server.URL, false)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating urlbuilder: %v", err)
|
||||
|
|
Loading…
Reference in a new issue