2018-03-28 02:15:52 +00:00
|
|
|
package azuremonitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetMetadata(t *testing.T) {
|
2018-05-03 09:11:31 +00:00
|
|
|
azureMetadata := &AzureMonitor{}
|
2018-03-28 02:15:52 +00:00
|
|
|
metadata, err := azureMetadata.GetInstanceMetadata()
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, metadata)
|
|
|
|
require.NotEmpty(t, metadata.AzureResourceID)
|
|
|
|
require.NotEmpty(t, metadata.Compute.Location)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
// t.Logf("could not get metadata: %v\n", err)
|
|
|
|
// } else {
|
|
|
|
// t.Logf("resource id \n%s", metadata.AzureResourceID)
|
|
|
|
// t.Logf("metadata is \n%v", metadata)
|
|
|
|
// }
|
|
|
|
|
|
|
|
//fmt.Printf("metadata is \n%v", metadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetTOKEN(t *testing.T) {
|
2018-05-03 09:11:31 +00:00
|
|
|
azureMetadata := &AzureMonitor{}
|
2018-03-28 02:15:52 +00:00
|
|
|
|
|
|
|
resourceID := "https://ingestion.monitor.azure.com/"
|
2018-04-29 07:31:24 +00:00
|
|
|
token, err := azureMetadata.getMsiToken("", resourceID)
|
2018-03-28 02:15:52 +00:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, token.AccessToken)
|
|
|
|
require.EqualValues(t, token.Resource, resourceID)
|
|
|
|
|
|
|
|
t.Logf("token is %+v\n", token)
|
|
|
|
t.Logf("expiry time is %s\n", token.ExpiresAt().Format(time.RFC3339))
|
|
|
|
t.Logf("expiry duration is %s\n", token.ExpiresInDuration().String())
|
|
|
|
t.Logf("resource is %s\n", token.Resource)
|
|
|
|
|
|
|
|
}
|