cloudwatch_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. provider := remoteCredProvider(&session.Session{})
  16. So(provider, ShouldNotBeNil)
  17. ecsProvider, ok := provider.(*endpointcreds.Provider)
  18. So(ecsProvider, ShouldNotBeNil)
  19. So(ok, ShouldBeTrue)
  20. So(ecsProvider.Client.Endpoint, ShouldEqual, fmt.Sprintf("http://169.254.170.2/abc/123"))
  21. })
  22. }
  23. func TestDefaultEC2RoleProvider(t *testing.T) {
  24. Convey("Running outside an ECS container task", t, func() {
  25. provider := remoteCredProvider(&session.Session{})
  26. So(provider, ShouldNotBeNil)
  27. ec2Provider, ok := provider.(*ec2rolecreds.EC2RoleProvider)
  28. So(ec2Provider, ShouldNotBeNil)
  29. So(ok, ShouldBeTrue)
  30. })
  31. }