conditions.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package clients
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. // RequireAdmin will restrict a test to only be run by admin users.
  7. func RequireAdmin(t *testing.T) {
  8. if os.Getenv("OS_USERNAME") != "admin" {
  9. t.Skip("must be admin to run this test")
  10. }
  11. }
  12. // RequireDNS will restrict a test to only be run in environments
  13. // that support DNSaaS.
  14. func RequireDNS(t *testing.T) {
  15. if os.Getenv("OS_DNS_ENVIRONMENT") == "" {
  16. t.Skip("this test requires DNSaaS")
  17. }
  18. }
  19. // RequireGuestAgent will restrict a test to only be run in
  20. // environments that support the QEMU guest agent.
  21. func RequireGuestAgent(t *testing.T) {
  22. if os.Getenv("OS_GUEST_AGENT") == "" {
  23. t.Skip("this test requires support for qemu guest agent and to set OS_GUEST_AGENT to 1")
  24. }
  25. }
  26. // RequireIdentityV2 will restrict a test to only be run in
  27. // environments that support the Identity V2 API.
  28. func RequireIdentityV2(t *testing.T) {
  29. if os.Getenv("OS_IDENTITY_API_VERSION") != "2.0" {
  30. t.Skip("this test requires support for the identity v2 API")
  31. }
  32. }
  33. // RequireLiveMigration will restrict a test to only be run in
  34. // environments that support live migration.
  35. func RequireLiveMigration(t *testing.T) {
  36. if os.Getenv("OS_LIVE_MIGRATE") == "" {
  37. t.Skip("this test requires support for live migration and to set OS_LIVE_MIGRATE to 1")
  38. }
  39. }
  40. // RequireLong will ensure long-running tests can run.
  41. func RequireLong(t *testing.T) {
  42. if testing.Short() {
  43. t.Skip("skipping test in short mode")
  44. }
  45. }
  46. // RequireNovaNetwork will restrict a test to only be run in
  47. // environments that support nova-network.
  48. func RequireNovaNetwork(t *testing.T) {
  49. if os.Getenv("OS_NOVANET") == "" {
  50. t.Skip("this test requires nova-network and to set OS_NOVANET to 1")
  51. }
  52. }