-
Notifications
You must be signed in to change notification settings - Fork 0
/
info_test.go
50 lines (44 loc) · 1.1 KB
/
info_test.go
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
package cloudinfo_test
import (
"bytes"
"encoding/json"
"log"
"net/netip"
"testing"
"github.com/KarpelesLab/cloudinfo"
)
func TestInfo(t *testing.T) {
nfo, _ := cloudinfo.Load()
log.Printf("info = %s", asJson(nfo))
nfo = &cloudinfo.Info{
Provider: "test",
AccountId: "123456",
Architecture: "x86_64",
PublicIP: cloudinfo.IPList{netip.MustParseAddr("1.2.3.4")},
PrivateIP: cloudinfo.IPList{netip.MustParseAddr("10.0.0.1")},
Hostname: "localhost.localdomain",
Image: "image-disk",
ID: "i-1232456",
Type: "testCloud",
Location: cloudinfo.LocationArray{
&cloudinfo.Location{"cloud", "test"},
&cloudinfo.Location{"zone", "testzone"},
},
DMI: &cloudinfo.DMI{
Cloud: "test",
Vendor: "test123",
ProductName: "unittest",
},
}
log.Printf("info = %s", asJson(nfo))
if nfo.Location.String() != "cloud=test,zone=testzone" {
t.Errorf("invalid location string: %s", nfo.Location)
}
}
func asJson(o any) []byte {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetIndent("", " ")
enc.Encode(o)
return buf.Bytes()
}