cloudwatch_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package cloudwatch
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
  7. "github.com/aws/aws-sdk-go/aws/credentials/endpointcreds"
  8. "github.com/aws/aws-sdk-go/aws/session"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestECSCredProvider(t *testing.T) {
  12. Convey("Running in an ECS container task", t, func() {
  13. defer os.Clearenv()
  14. os.Setenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "/abc/123")
  15. sess, _ := session.NewSession()
  16. provider := remoteCredProvider(sess)
  17. So(provider, ShouldNotBeNil)
  18. ecsProvider, ok := provider.(*endpointcreds.Provider)
  19. So(ecsProvider, ShouldNotBeNil)
  20. So(ok, ShouldBeTrue)
  21. So(ecsProvider.Client.Endpoint, ShouldEqual, fmt.Sprintf("http://169.254.170.2/abc/123"))
  22. })
  23. }
  24. func TestDefaultEC2RoleProvider(t *testing.T) {
  25. Convey("Running outside an ECS container task", t, func() {
  26. sess, _ := session.NewSession()
  27. provider := remoteCredProvider(sess)
  28. So(provider, ShouldNotBeNil)
  29. ec2Provider, ok := provider.(*ec2rolecreds.EC2RoleProvider)
  30. So(ec2Provider, ShouldNotBeNil)
  31. So(ok, ShouldBeTrue)
  32. })
  33. }