mirror of
https://github.com/distribution/distribution.git
synced 2025-08-23 00:57:53 +00:00
* Make copy poll max retry, a global driver max retry * Get support for etags in Azure * Fix storage driver tests * Fix auth mess and update docs * Refactor Azure client and enable Azure storage tests We use Azurite for integration testing which requires TLS, so we had to figure out how to skip TLS verification when running tests locally: this required updating testsuites Driver and constructor due to TestRedirectURL sending GET and HEAD requests to remote storage which in this case is Azurite. Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
105 lines
2.5 KiB
Go
105 lines
2.5 KiB
Go
package filesystem
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
|
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
|
)
|
|
|
|
func newDriverConstructor(tb testing.TB) testsuites.DriverConstructor {
|
|
root := tb.TempDir()
|
|
|
|
return func() (storagedriver.StorageDriver, error) {
|
|
return FromParameters(map[string]interface{}{
|
|
"rootdirectory": root,
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFilesystemDriverSuite(t *testing.T) {
|
|
testsuites.Driver(t, newDriverConstructor(t), false)
|
|
}
|
|
|
|
func BenchmarkFilesystemDriverSuite(b *testing.B) {
|
|
testsuites.BenchDriver(b, newDriverConstructor(b))
|
|
}
|
|
|
|
func TestFromParametersImpl(t *testing.T) {
|
|
tests := []struct {
|
|
params map[string]interface{} // technically the yaml can contain anything
|
|
expected DriverParameters
|
|
pass bool
|
|
}{
|
|
// check we use default threads and root dirs
|
|
{
|
|
params: map[string]interface{}{},
|
|
expected: DriverParameters{
|
|
RootDirectory: defaultRootDirectory,
|
|
MaxThreads: defaultMaxThreads,
|
|
},
|
|
pass: true,
|
|
},
|
|
// Testing initiation with a string maxThreads which can't be parsed
|
|
{
|
|
params: map[string]interface{}{
|
|
"maxthreads": "fail",
|
|
},
|
|
expected: DriverParameters{},
|
|
pass: false,
|
|
},
|
|
{
|
|
params: map[string]interface{}{
|
|
"maxthreads": "100",
|
|
},
|
|
expected: DriverParameters{
|
|
RootDirectory: defaultRootDirectory,
|
|
MaxThreads: uint64(100),
|
|
},
|
|
pass: true,
|
|
},
|
|
{
|
|
params: map[string]interface{}{
|
|
"maxthreads": 100,
|
|
},
|
|
expected: DriverParameters{
|
|
RootDirectory: defaultRootDirectory,
|
|
MaxThreads: uint64(100),
|
|
},
|
|
pass: true,
|
|
},
|
|
// check that we use minimum thread counts
|
|
{
|
|
params: map[string]interface{}{
|
|
"maxthreads": 1,
|
|
},
|
|
expected: DriverParameters{
|
|
RootDirectory: defaultRootDirectory,
|
|
MaxThreads: minThreads,
|
|
},
|
|
pass: true,
|
|
},
|
|
}
|
|
|
|
for _, item := range tests {
|
|
params, err := fromParametersImpl(item.params)
|
|
|
|
if !item.pass {
|
|
// We only need to assert that expected failures have an error
|
|
if err == nil {
|
|
t.Fatalf("expected error configuring filesystem driver with invalid param: %+v", item.params)
|
|
}
|
|
continue
|
|
}
|
|
|
|
if err != nil {
|
|
t.Fatalf("unexpected error creating filesystem driver: %s", err)
|
|
}
|
|
// Note that we get a pointer to params back
|
|
if !reflect.DeepEqual(*params, item.expected) {
|
|
t.Fatalf("unexpected params from filesystem driver. expected %+v, got %+v", item.expected, params)
|
|
}
|
|
}
|
|
}
|