Merge pull request #1024 from aaronlehmann/avoid-testing-import
Avoid importing "testing" in externally-facing code
This commit is contained in:
commit
ca2156d558
3 changed files with 10 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
package cache
|
package cachecheck
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -6,19 +6,20 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
|
"github.com/docker/distribution/registry/storage/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckBlobDescriptorCache takes a cache implementation through a common set
|
// CheckBlobDescriptorCache takes a cache implementation through a common set
|
||||||
// of operations. If adding new tests, please add them here so new
|
// of operations. If adding new tests, please add them here so new
|
||||||
// implementations get the benefit. This should be used for unit tests.
|
// implementations get the benefit. This should be used for unit tests.
|
||||||
func CheckBlobDescriptorCache(t *testing.T, provider BlobDescriptorCacheProvider) {
|
func CheckBlobDescriptorCache(t *testing.T, provider cache.BlobDescriptorCacheProvider) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
checkBlobDescriptorCacheEmptyRepository(t, ctx, provider)
|
checkBlobDescriptorCacheEmptyRepository(t, ctx, provider)
|
||||||
checkBlobDescriptorCacheSetAndRead(t, ctx, provider)
|
checkBlobDescriptorCacheSetAndRead(t, ctx, provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBlobDescriptorCacheEmptyRepository(t *testing.T, ctx context.Context, provider BlobDescriptorCacheProvider) {
|
func checkBlobDescriptorCacheEmptyRepository(t *testing.T, ctx context.Context, provider cache.BlobDescriptorCacheProvider) {
|
||||||
if _, err := provider.Stat(ctx, "sha384:abc"); err != distribution.ErrBlobUnknown {
|
if _, err := provider.Stat(ctx, "sha384:abc"); err != distribution.ErrBlobUnknown {
|
||||||
t.Fatalf("expected unknown blob error with empty store: %v", err)
|
t.Fatalf("expected unknown blob error with empty store: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +57,7 @@ func checkBlobDescriptorCacheEmptyRepository(t *testing.T, ctx context.Context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBlobDescriptorCacheSetAndRead(t *testing.T, ctx context.Context, provider BlobDescriptorCacheProvider) {
|
func checkBlobDescriptorCacheSetAndRead(t *testing.T, ctx context.Context, provider cache.BlobDescriptorCacheProvider) {
|
||||||
localDigest := digest.Digest("sha384:abc")
|
localDigest := digest.Digest("sha384:abc")
|
||||||
expected := distribution.Descriptor{
|
expected := distribution.Descriptor{
|
||||||
Digest: "sha256:abc",
|
Digest: "sha256:abc",
|
||||||
|
@ -140,7 +141,7 @@ func checkBlobDescriptorCacheSetAndRead(t *testing.T, ctx context.Context, provi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBlobDescriptorClear(t *testing.T, ctx context.Context, provider BlobDescriptorCacheProvider) {
|
func checkBlobDescriptorClear(t *testing.T, ctx context.Context, provider cache.BlobDescriptorCacheProvider) {
|
||||||
localDigest := digest.Digest("sha384:abc")
|
localDigest := digest.Digest("sha384:abc")
|
||||||
expected := distribution.Descriptor{
|
expected := distribution.Descriptor{
|
||||||
Digest: "sha256:abc",
|
Digest: "sha256:abc",
|
4
registry/storage/cache/memory/memory_test.go
vendored
4
registry/storage/cache/memory/memory_test.go
vendored
|
@ -3,11 +3,11 @@ package memory
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/distribution/registry/storage/cache"
|
"github.com/docker/distribution/registry/storage/cache/cachecheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestInMemoryBlobInfoCache checks the in memory implementation is working
|
// TestInMemoryBlobInfoCache checks the in memory implementation is working
|
||||||
// correctly.
|
// correctly.
|
||||||
func TestInMemoryBlobInfoCache(t *testing.T) {
|
func TestInMemoryBlobInfoCache(t *testing.T) {
|
||||||
cache.CheckBlobDescriptorCache(t, NewInMemoryBlobDescriptorCacheProvider())
|
cachecheck.CheckBlobDescriptorCache(t, NewInMemoryBlobDescriptorCacheProvider())
|
||||||
}
|
}
|
||||||
|
|
4
registry/storage/cache/redis/redis_test.go
vendored
4
registry/storage/cache/redis/redis_test.go
vendored
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/registry/storage/cache"
|
"github.com/docker/distribution/registry/storage/cache/cachecheck"
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,5 +47,5 @@ func TestRedisBlobDescriptorCacheProvider(t *testing.T) {
|
||||||
t.Fatalf("unexpected error flushing redis db: %v", err)
|
t.Fatalf("unexpected error flushing redis db: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.CheckBlobDescriptorCache(t, NewRedisBlobDescriptorCacheProvider(pool))
|
cachecheck.CheckBlobDescriptorCache(t, NewRedisBlobDescriptorCacheProvider(pool))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue