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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
//go:build integration && ec2env
// +build integration,ec2env
package imds
import (
"context"
"io/ioutil"
"os"
"strings"
"testing"
)
func TestInteg_GetDynamicData(t *testing.T) {
client := New(Options{})
result, err := client.GetDynamicData(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
b, err := ioutil.ReadAll(result.Content)
if err != nil {
t.Fatalf("expect to read content, got %v", err)
}
if len(b) == 0 {
t.Errorf("expect result content, but was empty")
}
t.Logf("Result:\n%s", string(b))
}
func TestInteg_GetIAMInfo(t *testing.T) {
client := New(Options{})
result, err := client.GetIAMInfo(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
t.Logf("IAMInfo:\n%#v", result.IAMInfo)
}
func TestInteg_GetInstanceIdentityDocument(t *testing.T) {
client := New(Options{})
result, err := client.GetInstanceIdentityDocument(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
t.Logf("InstanceIdentityDocument:\n%#v", result.InstanceIdentityDocument)
}
func TestInteg_GetMetadata(t *testing.T) {
client := New(Options{})
result, err := client.GetMetadata(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
b, err := ioutil.ReadAll(result.Content)
if err != nil {
t.Fatalf("expect to read content, got %v", err)
}
if len(b) == 0 {
t.Errorf("expect result content, but was empty")
}
t.Logf("Result:\n%s", string(b))
}
func TestInteg_GetRegion(t *testing.T) {
client := New(Options{})
result, err := client.GetRegion(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if len(result.Region) == 0 {
t.Errorf("expect region, got none")
}
t.Logf("Region: %s", result.Region)
}
func TestInteg_GetUserData(t *testing.T) {
if !strings.EqualFold(os.Getenv("AWS_TEST_EC2_IMDS_WITH_USER_DATA"), "true") {
t.Skip("to run test set AWS_TEST_EC2_IMDS_WITH_USER_DATA=true")
}
client := New(Options{})
result, err := client.GetUserData(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
b, err := ioutil.ReadAll(result.Content)
if err != nil {
t.Fatalf("expect to read content, got %v", err)
}
if len(b) == 0 {
t.Errorf("expect result content, but was empty")
}
t.Logf("Result:\n%s", string(b))
}
|