diff --git a/artifacttest/README.md b/artifacttest/README.md deleted file mode 100644 index 305c52b..0000000 --- a/artifacttest/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# artifacttest - -Этот пакет содержит тесты на [artifact](../distbuild/pkg/artifact). diff --git a/artifacttest/cache_test.go b/distbuild/pkg/artifact/cache_test.go similarity index 93% rename from artifacttest/cache_test.go rename to distbuild/pkg/artifact/cache_test.go index 69f2bf0..3055d3b 100644 --- a/artifacttest/cache_test.go +++ b/distbuild/pkg/artifact/cache_test.go @@ -1,4 +1,4 @@ -package artifacttest +package artifact_test import ( "errors" @@ -32,12 +32,13 @@ func newTestCache(t *testing.T) *testCache { } require.NoError(t, err) - return &testCache{Cache: cache, tmpDir: tmpDir} + c := &testCache{Cache: cache, tmpDir: tmpDir} + t.Cleanup(c.cleanup) + return c } func TestCache(t *testing.T) { c := newTestCache(t) - defer c.cleanup() idA := build.ID{'a'} @@ -73,7 +74,6 @@ func TestCache(t *testing.T) { func TestAbortWrite(t *testing.T) { c := newTestCache(t) - defer c.cleanup() idA := build.ID{'a'} @@ -87,7 +87,6 @@ func TestAbortWrite(t *testing.T) { func TestArtifactExists(t *testing.T) { c := newTestCache(t) - defer c.cleanup() idA := build.ID{'a'} diff --git a/artifacttest/client_test.go b/distbuild/pkg/artifact/client_test.go similarity index 93% rename from artifacttest/client_test.go rename to distbuild/pkg/artifact/client_test.go index 55b0222..37cc656 100644 --- a/artifacttest/client_test.go +++ b/distbuild/pkg/artifact/client_test.go @@ -1,4 +1,4 @@ -package artifacttest +package artifact_test import ( "context" @@ -17,9 +17,7 @@ import ( func TestArtifactTransfer(t *testing.T) { remoteCache := newTestCache(t) - defer remoteCache.cleanup() localCache := newTestCache(t) - defer localCache.cleanup() id := build.ID{0x01} diff --git a/filecachetest/client_test.go b/distbuild/pkg/filecache/client_test.go similarity index 92% rename from filecachetest/client_test.go rename to distbuild/pkg/filecache/client_test.go index 7331abb..ee30e7a 100644 --- a/filecachetest/client_test.go +++ b/distbuild/pkg/filecache/client_test.go @@ -29,16 +29,12 @@ func newEnv(t *testing.T) *env { mux := http.NewServeMux() cache := newCache(t) - defer func() { - if cache != nil { - cache.cleanup() - } - }() handler := filecache.NewHandler(l, cache.Cache) handler.Register(mux) server := httptest.NewServer(mux) + t.Cleanup(server.Close) client := filecache.NewClient(l, server.URL) @@ -48,19 +44,11 @@ func newEnv(t *testing.T) *env { client: client, } - cache = nil return env } -func (e *env) stop() { - e.server.Close() - e.cache.cleanup() -} - func TestFileUpload(t *testing.T) { env := newEnv(t) - defer env.stop() - content := bytes.Repeat([]byte("foobar"), 1024*1024) tmpFilePath := filepath.Join(env.cache.tmpDir, "foo.txt") @@ -115,10 +103,8 @@ func TestFileUpload(t *testing.T) { func TestFileDownload(t *testing.T) { env := newEnv(t) - defer env.stop() localCache := newCache(t) - defer localCache.cleanup() id := build.ID{0x01} diff --git a/filecachetest/filecache_test.go b/distbuild/pkg/filecache/filecache_test.go similarity index 93% rename from filecachetest/filecache_test.go rename to distbuild/pkg/filecache/filecache_test.go index 1d0d8a7..cac8d2d 100644 --- a/filecachetest/filecache_test.go +++ b/distbuild/pkg/filecache/filecache_test.go @@ -24,7 +24,9 @@ func newCache(t *testing.T) *testCache { c, err := filecache.New(tmpDir) require.NoError(t, err) - return &testCache{Cache: c, tmpDir: tmpDir} + cc := &testCache{Cache: c, tmpDir: tmpDir} + t.Cleanup(cc.cleanup) + return cc } func (c *testCache) cleanup() { diff --git a/tarstreamtest/stream_test.go b/distbuild/pkg/tarstream/stream_test.go similarity index 98% rename from tarstreamtest/stream_test.go rename to distbuild/pkg/tarstream/stream_test.go index dcae861..444da71 100644 --- a/tarstreamtest/stream_test.go +++ b/distbuild/pkg/tarstream/stream_test.go @@ -1,4 +1,4 @@ -package tarstreamtest +package tarstream_test import ( "bytes" diff --git a/filecachetest/README.md b/filecachetest/README.md deleted file mode 100644 index 16f4188..0000000 --- a/filecachetest/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# filecachetest - -Этот пакет содержит тесты на [filecache](../distbuild/pkg/filecache). diff --git a/tarstreamtest/README.md b/tarstreamtest/README.md deleted file mode 100644 index 4bf67e6..0000000 --- a/tarstreamtest/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# tarstreamtest - -Этот пакет содержит тесты на [tarstream](../distbuild/pkg/tarstream).