github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/cluster_discovery_test.go (about) 1 // Copyright (c) 2015-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 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestClusterDiscovery(t *testing.T) { 14 o := ClusterDiscovery{ 15 Type: "test_type", 16 ClusterName: "cluster_name", 17 Hostname: "test_hostname", 18 } 19 20 json := o.ToJson() 21 result1 := ClusterDiscoveryFromJson(strings.NewReader(json)) 22 23 assert.NotNil(t, result1) 24 assert.Equal(t, "cluster_name", result1.ClusterName) 25 26 result2 := ClusterDiscoveryFromJson(strings.NewReader(json)) 27 result3 := ClusterDiscoveryFromJson(strings.NewReader(json)) 28 29 o.Id = "0" 30 result1.Id = "1" 31 result2.Id = "2" 32 result3.Id = "3" 33 result3.Hostname = "something_diff" 34 35 assert.True(t, o.IsEqual(result1)) 36 37 list := make([]*ClusterDiscovery, 0) 38 list = append(list, &o) 39 list = append(list, result1) 40 list = append(list, result2) 41 list = append(list, result3) 42 43 rlist := FilterClusterDiscovery(list, func(in *ClusterDiscovery) bool { 44 return !o.IsEqual(in) 45 }) 46 47 assert.Len(t, rlist, 1) 48 49 o.AutoFillHostname() 50 o.Hostname = "" 51 o.AutoFillHostname() 52 53 o.AutoFillIpAddress("", "") 54 o.Hostname = "" 55 o.AutoFillIpAddress("", "") 56 }