-
Notifications
You must be signed in to change notification settings - Fork 491
/
storage_test.go
103 lines (84 loc) · 2.97 KB
/
storage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package provider_test
import (
"github.com/golang/mock/gomock"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"k8s.io/client-go/kubernetes"
"github.com/juju/juju/caas/kubernetes/provider"
"github.com/juju/juju/caas/kubernetes/provider/mocks"
"github.com/juju/juju/storage"
)
var _ = gc.Suite(&storageSuite{})
type storageSuite struct {
BaseSuite
k8sClient kubernetes.Interface
}
func (s *storageSuite) k8sProvider(c *gc.C, ctrl *gomock.Controller) storage.Provider {
s.k8sClient = mocks.NewMockInterface(ctrl)
return provider.StorageProvider(s.k8sClient, testNamespace)
}
func (s *storageSuite) TestValidateConfig(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
p := s.k8sProvider(c, ctrl)
cfg, err := storage.NewConfig("name", provider.K8s_ProviderType, map[string]interface{}{
"storage-class": "my-storage",
"storage-provisioner": "aws-storage",
"storage-label": "storage-fred",
})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
c.Assert(err, jc.ErrorIsNil)
c.Assert(cfg.Attrs(), jc.DeepEquals, map[string]interface{}{
"storage-class": "my-storage",
"storage-provisioner": "aws-storage",
"storage-label": "storage-fred",
})
}
func (s *storageSuite) TestValidateConfigError(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
p := s.k8sProvider(c, ctrl)
cfg, err := storage.NewConfig("name", provider.K8s_ProviderType, map[string]interface{}{
"storage-class": "",
"storage-provisioner": "aws-storage",
})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
c.Assert(err, gc.ErrorMatches, "storage-class must be specified if storage-provisioner is specified")
}
func (s *storageSuite) TestValidateConfigDefaultStorageClass(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
cfg, err := provider.NewStorageConfig(map[string]interface{}{"storage-provisioner": "ebs"})
c.Assert(err, jc.ErrorIsNil)
c.Assert(provider.StorageClass(cfg), gc.Equals, "juju-unit-storage")
}
func (s *storageSuite) TestNewStorageConfig(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
cfg, err := provider.NewStorageConfig(map[string]interface{}{
"storage-class": "juju-ebs",
"storage-provisioner": "ebs",
"parameters.type": "gp2",
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(provider.StorageClass(cfg), gc.Equals, "juju-ebs")
c.Assert(provider.StorageProvisioner(cfg), gc.Equals, "ebs")
c.Assert(provider.StorageParameters(cfg), jc.DeepEquals, map[string]string{"type": "gp2"})
}
func (s *storageSuite) TestSupports(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
p := s.k8sProvider(c, ctrl)
c.Assert(p.Supports(storage.StorageKindBlock), jc.IsFalse)
c.Assert(p.Supports(storage.StorageKindFilesystem), jc.IsTrue)
}
func (s *storageSuite) TestScope(c *gc.C) {
ctrl := s.setupBroker(c)
defer ctrl.Finish()
p := s.k8sProvider(c, ctrl)
c.Assert(p.Scope(), gc.Equals, storage.ScopeMachine)
}