1 package filesystem
2
3 import (
4 "io/ioutil"
5 "os"
6 "reflect"
7 "testing"
8
9 storagedriver "github.com/docker/distribution/registry/storage/driver"
10 "github.com/docker/distribution/registry/storage/driver/testsuites"
11 . "gopkg.in/check.v1"
12 )
13
14
15 func Test(t *testing.T) { TestingT(t) }
16
17 func init() {
18 root, err := ioutil.TempDir("", "driver-")
19 if err != nil {
20 panic(err)
21 }
22 defer os.Remove(root)
23
24 driver, err := FromParameters(map[string]interface{}{
25 "rootdirectory": root,
26 })
27 if err != nil {
28 panic(err)
29 }
30
31 testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
32 return driver, nil
33 }, testsuites.NeverSkip)
34 }
35
36 func TestFromParametersImpl(t *testing.T) {
37
38 tests := []struct {
39 params map[string]interface{}
40 expected DriverParameters
41 pass bool
42 }{
43
44 {
45 params: map[string]interface{}{},
46 expected: DriverParameters{
47 RootDirectory: defaultRootDirectory,
48 MaxThreads: defaultMaxThreads,
49 },
50 pass: true,
51 },
52
53 {
54 params: map[string]interface{}{
55 "maxthreads": "fail",
56 },
57 expected: DriverParameters{},
58 pass: false,
59 },
60 {
61 params: map[string]interface{}{
62 "maxthreads": "100",
63 },
64 expected: DriverParameters{
65 RootDirectory: defaultRootDirectory,
66 MaxThreads: uint64(100),
67 },
68 pass: true,
69 },
70 {
71 params: map[string]interface{}{
72 "maxthreads": 100,
73 },
74 expected: DriverParameters{
75 RootDirectory: defaultRootDirectory,
76 MaxThreads: uint64(100),
77 },
78 pass: true,
79 },
80
81 {
82 params: map[string]interface{}{
83 "maxthreads": 1,
84 },
85 expected: DriverParameters{
86 RootDirectory: defaultRootDirectory,
87 MaxThreads: minThreads,
88 },
89 pass: true,
90 },
91 }
92
93 for _, item := range tests {
94 params, err := fromParametersImpl(item.params)
95
96 if !item.pass {
97
98 if err == nil {
99 t.Fatalf("expected error configuring filesystem driver with invalid param: %+v", item.params)
100 }
101 continue
102 }
103
104 if err != nil {
105 t.Fatalf("unexpected error creating filesystem driver: %s", err)
106 }
107
108 if !reflect.DeepEqual(*params, item.expected) {
109 t.Fatalf("unexpected params from filesystem driver. expected %+v, got %+v", item.expected, params)
110 }
111 }
112
113 }
114
View as plain text