@@ -7,14 +7,12 @@ import (
77 "github.com/newrelic/nri-vsphere/internal/collect"
88 "github.com/newrelic/nri-vsphere/internal/config"
99 "github.com/newrelic/nri-vsphere/internal/model"
10- "github.com/newrelic/nri-vsphere/internal/process/testdata"
1110 "github.com/sirupsen/logrus"
1211 "github.com/stretchr/testify/assert"
1312 "github.com/vmware/govmomi/simulator"
1413 "github.com/vmware/govmomi/view"
1514 "github.com/vmware/govmomi/vim25"
1615 "github.com/vmware/govmomi/vim25/mo"
17- "github.com/vmware/govmomi/vim25/types"
1816 "testing"
1917)
2018
@@ -56,65 +54,3 @@ func getDatacenter(ctx context.Context, vm *view.Manager) *model.Datacenter {
5654 _ = cv .Retrieve (ctx , []string {"Datacenter" }, []string {"name" }, & datacenters )
5755 return model .NewDatacenter (& datacenters [0 ])
5856}
59-
60- const hostname = "test"
61- const fullHostname = "test.this.com"
62- const domain = "this.com"
63-
64- func TestComputeFullHostname (t * testing.T ) {
65- var vm = & mo.VirtualMachine {}
66- assert .Equal (t , "" , computeFullHostname (vm ))
67-
68- vm = & mo.VirtualMachine {
69- Guest : & types.GuestInfo {
70- IpStack : []types.GuestStackInfo {
71- {
72- DnsConfig : & types.NetDnsConfigInfo {
73- HostName : hostname + "different" ,
74- DomainName : domain ,
75- },
76- },
77- {
78- DnsConfig : & types.NetDnsConfigInfo {
79- HostName : hostname ,
80- },
81- },
82- {
83- DnsConfig : & types.NetDnsConfigInfo {
84- DomainName : domain ,
85- },
86- },
87- { // This is the only entry that the implementation should consider
88- DnsConfig : & types.NetDnsConfigInfo {
89- HostName : hostname ,
90- DomainName : domain ,
91- },
92- },
93- },
94- },
95- Summary : types.VirtualMachineSummary {
96- Guest : & types.VirtualMachineGuestSummary {
97- HostName : hostname ,
98- },
99- },
100- }
101- assert .Equal (t , fullHostname , computeFullHostname (vm ))
102-
103- // No matter if in hostname there is the fqdn, we do not place the suffix twice
104- vm .Guest .IpStack [3 ].DnsConfig .HostName = fullHostname
105- vm .Summary .Guest .HostName = fullHostname
106- assert .Equal (t , fullHostname , computeFullHostname (vm ))
107-
108- // No matter if in hostname there is the fqdn, we do not place the suffix twice
109- vm .Guest .IpStack [3 ].DnsConfig .HostName = hostname + "."
110- vm .Summary .Guest .HostName = hostname + "."
111- assert .Equal (t , fullHostname , computeFullHostname (vm ))
112-
113- // if the hostname is different in the summary we avoid computing the fqdn
114- vm .Guest .IpStack [3 ].DnsConfig .HostName = hostname + "different"
115- assert .Equal (t , "" , computeFullHostname (vm ))
116-
117- // Testing it with mock from real data
118- realVM := testdata .GetVMFromStaticData (t )
119- assert .Equal (t , "vm-3.test.com" , computeFullHostname (& realVM ))
120- }
0 commit comments