github.com/polarismesh/polaris@v1.17.8/test/integrate/config_file_test.go (about) 1 //go:build integration 2 // +build integration 3 4 /** 5 * Tencent is pleased to support the open source community by making Polaris available. 6 * 7 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 8 * 9 * Licensed under the BSD 3-Clause License (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * https://opensource.org/licenses/BSD-3-Clause 14 * 15 * Unless required by applicable law or agreed to in writing, software distributed 16 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations under the License. 19 */ 20 21 package test 22 23 import ( 24 "os" 25 "testing" 26 27 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage" 28 "github.com/stretchr/testify/assert" 29 "google.golang.org/protobuf/types/known/wrapperspb" 30 31 api "github.com/polarismesh/polaris/common/api/v1" 32 "github.com/polarismesh/polaris/common/utils" 33 "github.com/polarismesh/polaris/test/integrate/http" 34 "github.com/polarismesh/polaris/test/integrate/resource" 35 ) 36 37 func TestConfigCenter_ConfigFile(t *testing.T) { 38 client := http.NewClient(httpserverAddress, httpserverVersion) 39 40 ns := resource.CreateNamespaces() 41 42 groups := resource.MockConfigGroups(ns[0]) 43 44 files := resource.MockConfigFiles(groups[0]) 45 46 defer func() { 47 for i := range groups { 48 if _, err := client.DeleteConfigGroup(groups[i]); err != nil { 49 t.Log(err) 50 } 51 } 52 client.DeleteNamespaces(ns) 53 os.Remove("export.zip") 54 }() 55 56 t.Run("配置中心-创建配置文件", func(t *testing.T) { 57 for _, file := range files { 58 resp, err := client.CreateConfigFile(file) 59 if err != nil { 60 t.Fatal(err) 61 } 62 assert.Equal(t, resp.GetCode().GetValue(), api.ExecuteSuccess, resp.GetInfo().GetValue()) 63 } 64 }) 65 66 t.Run("配置中心-更新配置文件", func(t *testing.T) { 67 for _, file := range files { 68 file.Content = &wrapperspb.StringValue{ 69 Value: `name: polarismesh_test`, 70 } 71 resp, err := client.UpdateConfigFile(file) 72 if err != nil { 73 t.Fatal(err) 74 } 75 assert.Equal(t, resp.GetCode().GetValue(), api.ExecuteSuccess, resp.GetInfo().GetValue()) 76 } 77 }) 78 79 t.Run("配置中心-导出配置文件", func(t *testing.T) { 80 req := &apiconfig.ConfigFileExportRequest{ 81 Namespace: ns[0].Name, 82 Groups: []*wrapperspb.StringValue{ 83 groups[0].Name, 84 }, 85 } 86 err := client.ExportConfigFile(req) 87 if err != nil { 88 t.Fatal(err) 89 } 90 }) 91 92 t.Run("配置中心-导入配置文件", func(t *testing.T) { 93 namespace := ns[1].Name.Value 94 conflictHandling := utils.ConfigFileImportConflictSkip 95 resp, err := client.ImportConfigFile(namespace, "", conflictHandling) 96 if err != nil { 97 t.Fatal(err) 98 } 99 assert.Equal(t, resp.GetCode().GetValue(), api.ExecuteSuccess, resp.GetInfo().GetValue()) 100 }) 101 102 t.Run("配置中心-删除配置文件", func(t *testing.T) { 103 for _, file := range files { 104 resp, err := client.DeleteConfigFile(file) 105 if err != nil { 106 t.Fatal(err) 107 } 108 assert.Equal(t, resp.GetCode().GetValue(), api.ExecuteSuccess, resp.GetInfo().GetValue()) 109 } 110 }) 111 112 t.Run("配置中心-获取全部加密算法", func(t *testing.T) { 113 resp, err := client.GetAllConfigEncryptAlgorithms() 114 if err != nil { 115 t.Fatal(err) 116 } 117 assert.Equal(t, resp.GetCode().GetValue(), api.ExecuteSuccess, resp.GetInfo().GetValue()) 118 }) 119 }