forked from cloudscale-ch/cloudscale-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_test.go
46 lines (36 loc) · 985 Bytes
/
metadata_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
package cloudscale
import (
"fmt"
"net/http"
"testing"
)
func TestServerId(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/openstack/2017-02-22/meta_data.json", func(w http.ResponseWriter, r *http.Request) {
testHTTPMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"meta": {"cloudscale_uuid": "foobar"}}`)
})
serverID, err := metadataClient.GetServerID()
if err != nil {
t.Errorf("GetServerID returned error: %v", err)
}
if serverID != "foobar" {
t.Errorf("expected id 'foobar', received '%s'", serverID)
}
}
func TestRawUserData(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/openstack/2017-02-22/user_data", func(w http.ResponseWriter, r *http.Request) {
testHTTPMethod(t, r, http.MethodGet)
fmt.Fprint(w, `abcdef`)
})
userData, err := metadataClient.GetRawUserData()
if err != nil {
t.Errorf("Server.Get returned error: %v", err)
}
if userData != "abcdef" {
t.Errorf("expected 'abcdef', received '%s'", userData)
}
}