github.com/polarismesh/polaris@v1.17.8/test/integrate/service_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 "testing" 25 26 "github.com/polarismesh/polaris/test/integrate/http" 27 "github.com/polarismesh/polaris/test/integrate/resource" 28 ) 29 30 // TestService 测试增删改查服务 31 func TestService(t *testing.T) { 32 t.Log("test service interface") 33 34 client := http.NewClient(httpserverAddress, httpserverVersion) 35 36 namespaces := resource.CreateNamespaces() 37 38 // 创建命名空间 39 ret, err := client.CreateNamespaces(namespaces) 40 if err != nil { 41 t.Fatalf("create namespaces fail, err is %v", err) 42 } 43 for index, item := range ret.GetResponses() { 44 namespaces[index].Token = item.GetNamespace().GetToken() 45 } 46 t.Log("create namespaces success") 47 48 // ------------------------------------------------------- 49 50 services := resource.CreateServices(namespaces[0]) 51 52 // 创建服务 53 ret, err = client.CreateServices(services) 54 if err != nil { 55 t.Fatalf("create services fail, err is %v", err) 56 } 57 for index, item := range ret.GetResponses() { 58 services[index].Token = item.GetService().GetToken() 59 } 60 t.Log("create services success") 61 62 // 查询服务 63 err = client.GetServices(services) 64 if err != nil { 65 t.Fatalf("get services fail, err is %v", err) 66 } 67 t.Log("get services success") 68 69 // 更新服务 70 resource.UpdateServices(services) 71 72 err = client.UpdateServices(services) 73 if err != nil { 74 t.Fatalf("update services fail, err is %v", err) 75 } 76 t.Log("update services success") 77 78 // 查询服务 79 err = client.GetServices(services) 80 if err != nil { 81 t.Fatalf("get services fail, err is %v", err) 82 } 83 t.Log("get services success") 84 85 // 删除服务 86 err = client.DeleteServices(services) 87 if err != nil { 88 t.Fatalf("delete services fail, err is %v", err) 89 } 90 t.Log("delete services success") 91 92 // ------------------------------------------------------- 93 94 // 删除命名空间 95 err = client.DeleteNamespaces(namespaces) 96 if err != nil { 97 t.Fatalf("delete namespaces fail, err is %v", err) 98 } 99 t.Log("delete namespaces success") 100 }