2022-07-13 20:43:18 +00:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
2022-11-30 05:22:12 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
2022-07-13 20:43:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppendMachineLabels(t *testing.T) {
|
2022-11-30 05:22:12 +00:00
|
|
|
f := func(name string, vms []virtualMachine, expectedLabels []*promutils.Labels) {
|
2022-07-13 20:43:18 +00:00
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
labelss := appendMachineLabels(vms, 80, &SDConfig{SubscriptionID: "some-id"})
|
2022-11-30 05:22:12 +00:00
|
|
|
discoveryutils.TestEqualLabelss(t, labelss, expectedLabels)
|
2022-07-13 20:43:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
f("single vm", []virtualMachine{
|
|
|
|
{
|
2023-01-28 01:07:10 +00:00
|
|
|
Name: "vm-1",
|
|
|
|
ID: "id-2",
|
|
|
|
Type: "Azure",
|
|
|
|
Location: "eu-west-1",
|
|
|
|
Properties: virtualMachineProperties{
|
|
|
|
OsProfile: osProfile{ComputerName: "test-1"},
|
|
|
|
StorageProfile: storageProfile{OsDisk: osDisk{OsType: "Linux"}},
|
|
|
|
HardwareProfile: hardwareProfile{VMSize: "big"},
|
|
|
|
},
|
|
|
|
Tags: map[string]string{"key-1": "value-1"},
|
2022-07-13 20:43:18 +00:00
|
|
|
ipAddresses: []vmIPAddress{
|
|
|
|
{privateIP: "10.10.10.1"},
|
|
|
|
},
|
|
|
|
},
|
2022-11-30 05:22:12 +00:00
|
|
|
}, []*promutils.Labels{
|
|
|
|
promutils.NewLabelsFromMap(map[string]string{
|
2022-07-13 20:43:18 +00:00
|
|
|
"__address__": "10.10.10.1:80",
|
|
|
|
"__meta_azure_machine_id": "id-2",
|
|
|
|
"__meta_azure_subscription_id": "some-id",
|
|
|
|
"__meta_azure_machine_os_type": "Linux",
|
|
|
|
"__meta_azure_machine_name": "vm-1",
|
|
|
|
"__meta_azure_machine_computer_name": "test-1",
|
|
|
|
"__meta_azure_machine_location": "eu-west-1",
|
|
|
|
"__meta_azure_machine_private_ip": "10.10.10.1",
|
2023-01-28 01:07:10 +00:00
|
|
|
"__meta_azure_machine_size": "big",
|
2022-07-13 20:43:18 +00:00
|
|
|
"__meta_azure_machine_tag_key_1": "value-1",
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|