github.com/polarismesh/polaris@v1.17.8/test/integrate/uplower_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  	"time"
    26  
    27  	"github.com/ArthurHlt/go-eureka-client/eureka"
    28  )
    29  
    30  // TestEurekaServer_RegisterApplication 测试EurekaServer大小写
    31  func TestEurekaServer_RegisterApplication(t *testing.T) {
    32  	var err error
    33  	client := eureka.NewClient([]string{
    34  		"http://127.0.0.1:8761/eureka", //From a spring boot based eureka server
    35  	})
    36  	appId := "testAPP"
    37  	//err = client.UnregisterInstance(appId, "4d5c2ab8417452dbd62619359e6116d1eec42a52")
    38  	//if err != nil {
    39  	//	t.Fatalf("Eureka UnregisterInstance Error:%+v", err)
    40  	//}
    41  
    42  	instance := eureka.NewInstanceInfo("TEST", appId, "1.1.1.1", 80, 30, false) //Create a new instance to register
    43  	instance.Metadata = &eureka.MetaData{
    44  		Map: make(map[string]string),
    45  	}
    46  	instance.Metadata.Map["foo"] = "bar" //add metadata for example
    47  
    48  	err = client.RegisterInstance(appId, instance) // Register new instance in your eureka(s)
    49  	if err != nil {
    50  		t.Fatal(err)
    51  	}
    52  	time.Sleep(15 * time.Second)
    53  
    54  	applications, _ := client.GetApplications() // Retrieves all applications from eureka server(s)
    55  	t.Log(applications)
    56  
    57  	_, err = client.GetApplication(appId)
    58  	if err != nil {
    59  		t.Fatalf("Eureka GetApplication Error:%+v", err)
    60  	}
    61  
    62  }