-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy pathconfig_file_template_test.go
86 lines (76 loc) · 3.22 KB
/
config_file_template_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
/*
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 config
import (
api "github.com/polarismesh/polaris-server/common/api/v1"
"github.com/polarismesh/polaris-server/common/utils"
"github.com/stretchr/testify/assert"
"testing"
)
// TestConfigFileTemplateCRUD the base test for config file template
func TestConfigFileTemplateCRUD(t *testing.T) {
testSuit, err := newConfigCenterTest(t)
if err != nil {
t.Fatal(err)
}
defer func() {
if err := testSuit.clearTestData(); err != nil {
t.Fatal(err)
}
}()
templateName := "t1"
t.Run("first-query", func(t *testing.T) {
queryRsp := testSuit.testService.GetConfigFileTemplate(testSuit.defaultCtx, templateName)
assert.Equal(t, api.NotFoundResource, queryRsp.Code.Value)
})
template1 := assembleConfigFileTemplate(templateName)
t.Run("first-create", func(t *testing.T) {
createRsp := testSuit.testService.CreateConfigFileTemplate(testSuit.defaultCtx, template1)
assert.Equal(t, api.ExecuteSuccess, createRsp.Code.GetValue())
//repeat create
createRsp = testSuit.testService.CreateConfigFileTemplate(testSuit.defaultCtx, template1)
assert.Equal(t, api.BadRequest, createRsp.Code.GetValue())
})
t.Run("second-query", func(t *testing.T) {
queryRsp := testSuit.testService.GetConfigFileTemplate(testSuit.defaultCtx, templateName)
assert.Equal(t, api.ExecuteSuccess, queryRsp.Code.Value)
assert.Equal(t, template1.Name.GetValue(), queryRsp.ConfigFileTemplate.Name.GetValue())
assert.Equal(t, template1.Content.GetValue(), queryRsp.ConfigFileTemplate.Content.GetValue())
assert.Equal(t, template1.Comment.GetValue(), queryRsp.ConfigFileTemplate.Comment.GetValue())
assert.Equal(t, template1.Format.GetValue(), queryRsp.ConfigFileTemplate.Format.GetValue())
})
template2 := assembleConfigFileTemplate("t2")
t.Run("second-create", func(t *testing.T) {
createRsp := testSuit.testService.CreateConfigFileTemplate(testSuit.defaultCtx, template2)
assert.Equal(t, api.ExecuteSuccess, createRsp.Code.GetValue())
})
t.Run("query-all", func(t *testing.T) {
rsp := testSuit.testService.GetAllConfigFileTemplates(testSuit.defaultCtx)
assert.Equal(t, api.ExecuteSuccess, rsp.Code.GetValue())
assert.Equal(t, 2, len(rsp.ConfigFileTemplates))
})
}
func assembleConfigFileTemplate(name string) *api.ConfigFileTemplate {
return &api.ConfigFileTemplate{
Name: utils.NewStringValue(name),
Content: utils.NewStringValue("some content"),
Comment: utils.NewStringValue("comment"),
Format: utils.NewStringValue("json"),
CreateBy: utils.NewStringValue("testUser"),
ModifyBy: utils.NewStringValue("testUser"),
}
}