2014-10-21 22:02:20 +00:00
|
|
|
package filesystem
|
|
|
|
|
|
|
|
import (
|
2014-12-04 00:44:20 +00:00
|
|
|
"io/ioutil"
|
2014-10-21 22:02:20 +00:00
|
|
|
"os"
|
2016-04-26 21:36:38 +00:00
|
|
|
"reflect"
|
2014-10-21 22:02:20 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-08-24 11:18:39 +00:00
|
|
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
|
|
|
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
2014-10-21 22:02:20 +00:00
|
|
|
. "gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hook up gocheck into the "go test" runner.
|
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
|
|
|
func init() {
|
2014-12-04 00:44:20 +00:00
|
|
|
root, err := ioutil.TempDir("", "driver-")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2014-10-21 22:02:20 +00:00
|
|
|
}
|
2014-12-04 00:44:20 +00:00
|
|
|
defer os.Remove(root)
|
|
|
|
|
2016-04-26 21:36:38 +00:00
|
|
|
driver, err := FromParameters(map[string]interface{}{
|
|
|
|
"rootdirectory": root,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-06-29 23:39:45 +00:00
|
|
|
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
|
2016-04-26 21:36:38 +00:00
|
|
|
return driver, nil
|
2014-12-04 00:44:20 +00:00
|
|
|
}, testsuites.NeverSkip)
|
2014-10-21 22:02:20 +00:00
|
|
|
}
|
2016-04-26 21:36:38 +00:00
|
|
|
|
|
|
|
func TestFromParametersImpl(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
2019-10-09 12:02:21 +00:00
|
|
|
params map[string]interface{} // technically the yaml can contain anything
|
2016-04-26 21:36:38 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|