github.com/nhannv/mattermost-server@v5.11.1+incompatible/model/cluster_discovery_test.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestClusterDiscovery(t *testing.T) {
    12  	o := ClusterDiscovery{
    13  		Type:        "test_type",
    14  		ClusterName: "cluster_name",
    15  		Hostname:    "test_hostname",
    16  	}
    17  
    18  	json := o.ToJson()
    19  	result1 := ClusterDiscoveryFromJson(strings.NewReader(json))
    20  
    21  	if result1.ClusterName != "cluster_name" {
    22  		t.Fatal("should be set")
    23  	}
    24  
    25  	result2 := ClusterDiscoveryFromJson(strings.NewReader(json))
    26  	result3 := ClusterDiscoveryFromJson(strings.NewReader(json))
    27  
    28  	o.Id = "0"
    29  	result1.Id = "1"
    30  	result2.Id = "2"
    31  	result3.Id = "3"
    32  	result3.Hostname = "something_diff"
    33  
    34  	if !o.IsEqual(result1) {
    35  		t.Fatal("Should be equal")
    36  	}
    37  
    38  	list := make([]*ClusterDiscovery, 0)
    39  	list = append(list, &o)
    40  	list = append(list, result1)
    41  	list = append(list, result2)
    42  	list = append(list, result3)
    43  
    44  	rlist := FilterClusterDiscovery(list, func(in *ClusterDiscovery) bool {
    45  		return !o.IsEqual(in)
    46  	})
    47  
    48  	if len(rlist) != 1 {
    49  		t.Fatal("should only have 1 result")
    50  	}
    51  
    52  	o.AutoFillHostname()
    53  	o.Hostname = ""
    54  	o.AutoFillHostname()
    55  
    56  	o.AutoFillIpAddress()
    57  	o.Hostname = ""
    58  	o.AutoFillIpAddress()
    59  }