github.com/leeclow-ops/gophercloud@v1.2.1/acceptance/clients/conditions.go (about)

     1  package clients
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  // RequireAdmin will restrict a test to only be run by admin users.
     9  func RequireAdmin(t *testing.T) {
    10  	if os.Getenv("OS_USERNAME") != "admin" {
    11  		t.Skip("must be admin to run this test")
    12  	}
    13  }
    14  
    15  // RequireNonAdmin will restrict a test to only be run by non-admin users.
    16  func RequireNonAdmin(t *testing.T) {
    17  	if os.Getenv("OS_USERNAME") == "admin" {
    18  		t.Skip("must be a non-admin to run this test")
    19  	}
    20  }
    21  
    22  // RequirePortForwarding will restrict a test to only be run in environments
    23  // that support port forwarding
    24  func RequirePortForwarding(t *testing.T) {
    25  	if os.Getenv("OS_PORTFORWARDING_ENVIRONMENT") == "" {
    26  		t.Skip("this test requires support for port forwarding")
    27  	}
    28  }
    29  
    30  // RequireGuestAgent will restrict a test to only be run in
    31  // environments that support the QEMU guest agent.
    32  func RequireGuestAgent(t *testing.T) {
    33  	if os.Getenv("OS_GUEST_AGENT") == "" {
    34  		t.Skip("this test requires support for qemu guest agent and to set OS_GUEST_AGENT to 1")
    35  	}
    36  }
    37  
    38  // RequireIdentityV2 will restrict a test to only be run in
    39  // environments that support the Identity V2 API.
    40  func RequireIdentityV2(t *testing.T) {
    41  	if os.Getenv("OS_IDENTITY_API_VERSION") != "2.0" {
    42  		t.Skip("this test requires support for the identity v2 API")
    43  	}
    44  }
    45  
    46  // RequireLiveMigration will restrict a test to only be run in
    47  // environments that support live migration.
    48  func RequireLiveMigration(t *testing.T) {
    49  	if os.Getenv("OS_LIVE_MIGRATE") == "" {
    50  		t.Skip("this test requires support for live migration and to set OS_LIVE_MIGRATE to 1")
    51  	}
    52  }
    53  
    54  // RequireLong will ensure long-running tests can run.
    55  func RequireLong(t *testing.T) {
    56  	if testing.Short() {
    57  		t.Skip("skipping test in short mode")
    58  	}
    59  }
    60  
    61  // RequireNovaNetwork will restrict a test to only be run in
    62  // environments that support nova-network.
    63  func RequireNovaNetwork(t *testing.T) {
    64  	if os.Getenv("OS_NOVANET") == "" {
    65  		t.Skip("this test requires nova-network and to set OS_NOVANET to 1")
    66  	}
    67  }
    68  
    69  // RequireIronicHTTPBasic will restric a test to be only run in
    70  // environments that have Ironic using http_basic.
    71  func RequireIronicHTTPBasic(t *testing.T) {
    72  	if os.Getenv("IRONIC_ENDPOINT") == "" || os.Getenv("OS_USERNAME") == "" || os.Getenv("OS_PASSWORD") == "" {
    73  		t.Skip("this test requires Ironic using http_basic, set OS_USERNAME, OS_PASSWORD and IRONIC_ENDPOINT")
    74  	}
    75  }
    76  
    77  // SkipRelease will have the test be skipped on a certain
    78  // release. Releases are named such as 'stable/mitaka', master, etc.
    79  func SkipRelease(t *testing.T, release string) {
    80  	if os.Getenv("OS_BRANCH") == release {
    81  		t.Skipf("this is not supported in %s", release)
    82  	}
    83  }
    84  
    85  // SkipReleasesBelow will have the test be skipped on releases below a certain
    86  // one. Releases are named such as 'stable/mitaka', master, etc.
    87  func SkipReleasesBelow(t *testing.T, release string) {
    88  	current_branch := os.Getenv("OS_BRANCH")
    89  
    90  	if IsReleasesBelow(t, release) {
    91  		t.Skipf("this is not supported below %s, testing in %s", release, current_branch)
    92  	}
    93  }
    94  
    95  // SkipReleasesAbove will have the test be skipped on releases above a certain
    96  // one. The test is always skipped on master release. Releases are named such
    97  // as 'stable/mitaka', master, etc.
    98  func SkipReleasesAbove(t *testing.T, release string) {
    99  	current_branch := os.Getenv("OS_BRANCH")
   100  
   101  	// Assume master is always too new
   102  	if IsReleasesAbove(t, release) {
   103  		t.Skipf("this is not supported above %s, testing in %s", release, current_branch)
   104  	}
   105  }
   106  
   107  // IsReleasesAbove will return true on releases above a certain
   108  // one. The result is always true on master release. Releases are named such
   109  // as 'stable/mitaka', master, etc.
   110  func IsReleasesAbove(t *testing.T, release string) bool {
   111  	current_branch := os.Getenv("OS_BRANCH")
   112  
   113  	// Assume master is always too new
   114  	if current_branch == "master" || current_branch > release {
   115  		return true
   116  	}
   117  	t.Logf("Target release %s is below the current branch %s", release, current_branch)
   118  	return false
   119  }
   120  
   121  // IsReleasesBelow will return true on releases below a certain
   122  // one. Releases are named such as 'stable/mitaka', master, etc.
   123  func IsReleasesBelow(t *testing.T, release string) bool {
   124  	current_branch := os.Getenv("OS_BRANCH")
   125  
   126  	if current_branch != "master" && current_branch < release {
   127  		return true
   128  	}
   129  	t.Logf("Target release %s is above the current branch %s", release, current_branch)
   130  	return false
   131  }