integration.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. if aws.StringValue(Session.Config.Region) == "" {
  28. panic("AWS_REGION must be configured to run integration tests")
  29. }
  30. }
  31. // UniqueID returns a unique UUID-like identifier for use in generating
  32. // resources for integration tests.
  33. func UniqueID() string {
  34. uuid := make([]byte, 16)
  35. io.ReadFull(rand.Reader, uuid)
  36. return fmt.Sprintf("%x", uuid)
  37. }