summaryrefslogtreecommitdiffstats
path: root/model/cluster_discovery_test.go
blob: bfbdbd303d2a1291b5ec5e3140fe11d5a8d61c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
)

func TestClusterDiscovery(t *testing.T) {
	o := ClusterDiscovery{
		Type:        "test_type",
		ClusterName: "cluster_name",
		Hostname:    "test_hostname",
	}

	json := o.ToJson()
	result1 := ClusterDiscoveryFromJson(strings.NewReader(json))

	if result1.ClusterName != "cluster_name" {
		t.Fatal("should be set")
	}

	result2 := ClusterDiscoveryFromJson(strings.NewReader(json))
	result3 := ClusterDiscoveryFromJson(strings.NewReader(json))

	o.Id = "0"
	result1.Id = "1"
	result2.Id = "2"
	result3.Id = "3"
	result3.Hostname = "something_diff"

	if !o.IsEqual(result1) {
		t.Fatal("Should be equal")
	}

	list := make([]*ClusterDiscovery, 0)
	list = append(list, &o)
	list = append(list, result1)
	list = append(list, result2)
	list = append(list, result3)

	rlist := FilterClusterDiscovery(list, func(in *ClusterDiscovery) bool {
		return !o.IsEqual(in)
	})

	if len(rlist) != 1 {
		t.Fatal("should only have 1 result")
	}

	o.AutoFillHostname()
	o.Hostname = ""
	o.AutoFillHostname()

	o.AutoFillIpAddress()
	o.Hostname = ""
	o.AutoFillIpAddress()
}