integration.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // +build integration
  2. // Package integration performs initialization and validation for integration
  3. // tests.
  4. package integration
  5. import (
  6. "crypto/rand"
  7. "fmt"
  8. "io"
  9. "os"
  10. "github.com/aws/aws-sdk-go/aws"
  11. "github.com/aws/aws-sdk-go/aws/session"
  12. )
  13. // Session is a shared session for all integration tests to use.
  14. var Session = session.Must(session.NewSession())
  15. func init() {
  16. logLevel := Session.Config.LogLevel
  17. if os.Getenv("DEBUG") != "" {
  18. logLevel = aws.LogLevel(aws.LogDebug)
  19. }
  20. if os.Getenv("DEBUG_SIGNING") != "" {
  21. logLevel = aws.LogLevel(aws.LogDebugWithSigning)
  22. }
  23. if os.Getenv("DEBUG_BODY") != "" {
  24. logLevel = aws.LogLevel(aws.LogDebugWithSigning | aws.LogDebugWithHTTPBody)
  25. }
  26. Session.Config.LogLevel = logLevel
  27. }
  28. // UniqueID returns a unique UUID-like identifier for use in generating
  29. // resources for integration tests.
  30. func UniqueID() string {
  31. uuid := make([]byte, 16)
  32. io.ReadFull(rand.Reader, uuid)
  33. return fmt.Sprintf("%x", uuid)
  34. }
  35. // SessionWithDefaultRegion returns a copy of the integration session with the
  36. // region set if one was not already provided.
  37. func SessionWithDefaultRegion(region string) *session.Session {
  38. sess := Session.Copy()
  39. if v := aws.StringValue(sess.Config.Region); len(v) == 0 {
  40. sess.Config.Region = aws.String(region)
  41. }
  42. return sess
  43. }