-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_createBlock_api_test.go
159 lines (129 loc) · 5.25 KB
/
block_createBlock_api_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integration
import (
"strings"
"testing"
"github.com/rook/rook/pkg/model"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/contracts"
"github.com/rook/rook/tests/framework/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
var (
pool1 = "rook_test_pool1"
pool2 = "rook_test_pool2"
blockImageName = "testImage"
)
func TestBlockImageCreateSuite(t *testing.T) {
s := new(BlockImageCreateSuite)
defer func(s *BlockImageCreateSuite) {
HandlePanics(recover(), s.op, s.T)
}(s)
suite.Run(t, s)
}
type BlockImageCreateSuite struct {
suite.Suite
testClient *clients.TestClient
kh *utils.K8sHelper
rc contracts.RestAPIOperator
op contracts.Setup
initBlockCount int
namespace string
}
func (s *BlockImageCreateSuite) SetupSuite() {
var err error
s.namespace = "block-api-ns"
s.op, s.kh = NewBaseTestOperations(s.T, s.namespace, "bluestore", "", false, false, 1)
s.testClient = GetTestClient(s.kh, s.namespace, s.op, s.T)
s.rc = s.testClient.GetRestAPIClient()
initialBlocks, err := s.rc.GetBlockImages()
assert.Nil(s.T(), err)
s.initBlockCount = len(initialBlocks)
}
//Test Creating Block image on custom pool
func (s *BlockImageCreateSuite) TestCreatingNewBlockImageOnCustomPool() {
s.T().Log("Test Creating new block image for custom pool")
newPool := model.Pool{Name: pool1, ReplicatedConfig: model.ReplicatedPoolConfig{Size: 1}}
_, err := s.rc.CreatePool(newPool)
require.Nil(s.T(), err)
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: newPool.Name}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
//Test Creating Block image twice on same pool
func (s *BlockImageCreateSuite) TestRecreatingBlockImageForSamePool() {
s.T().Log("Test Case when Block Image is created with Name that is already used by another block on same pool")
//create pool1
newPool1 := model.Pool{Name: pool1, ReplicatedConfig: model.ReplicatedPoolConfig{Size: 1}}
_, err := s.rc.CreatePool(newPool1)
require.Nil(s.T(), err)
// create new block image
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: pool1}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
//create same block again on same pool
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: pool1}
cbi2, err := s.rc.CreateBlockImage(newImage2)
require.Error(s.T(), err, "Make sure dupe block is not created")
require.NotContains(s.T(), cbi2, "succeeded created image")
b2, _ := s.rc.GetBlockImages()
require.Equal(s.T(), len(b), len(b2), "Make sure new block image is not created")
}
//Test Creating Block image twice on different pool
func (s *BlockImageCreateSuite) TestRecreatingBlockImageForDifferentPool() {
s.T().Log("Test Case when Block Image is created with Name that is already used by another block on different pool")
//create pool1
newPool1 := model.Pool{Name: pool1, ReplicatedConfig: model.ReplicatedPoolConfig{Size: 1}}
_, err := s.rc.CreatePool(newPool1)
require.Nil(s.T(), err)
//create pool2
newPool2 := model.Pool{Name: pool2, ReplicatedConfig: model.ReplicatedPoolConfig{Size: 1}}
_, err = s.rc.CreatePool(newPool2)
require.Nil(s.T(), err)
// create new block image
newImage := model.BlockImage{Name: blockImageName, Size: 123, PoolName: pool1}
cbi, err := s.rc.CreateBlockImage(newImage)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi, "succeeded created image")
b, _ := s.rc.GetBlockImages()
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
//create same block again on different pool
newImage2 := model.BlockImage{Name: blockImageName, Size: 2897, PoolName: pool2}
cbi2, err := s.rc.CreateBlockImage(newImage2)
require.Nil(s.T(), err)
require.Contains(s.T(), cbi2, "succeeded created image")
b2, _ := s.rc.GetBlockImages()
require.Equal(s.T(), len(b)+1, len(b2), "Make sure new block image is created")
}
// Delete all Block images that have the word Test in their name
func (s *BlockImageCreateSuite) TearDownTest() {
blocks, err := s.rc.GetBlockImages()
assert.NoError(s.T(), err)
for _, b := range blocks {
if strings.Contains(b.Name, "test") {
s.rc.DeleteBlockImage(b)
}
}
}
func (s *BlockImageCreateSuite) TearDownSuite() {
s.op.TearDown()
}