github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/client_credentials.go (about)

     1  package helpers
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  // SkipIfClientCredentialsNotSet will skip the test when either
    12  // CF_INT_CLIENT_ID or CF_INT_CLIENT_SECRET are not set.
    13  func SkipIfClientCredentialsNotSet() (string, string) {
    14  	privateClientID := os.Getenv("CF_INT_CLIENT_ID")
    15  	privateClientSecret := os.Getenv("CF_INT_CLIENT_SECRET")
    16  
    17  	if privateClientID == "" || privateClientSecret == "" {
    18  		Skip("CF_INT_CLIENT_ID or CF_INT_CLIENT_SECRET is not set")
    19  	}
    20  
    21  	return privateClientID, privateClientSecret
    22  }
    23  
    24  // SkipIfCustomClientCredentialsNotSet will skip the test when either
    25  // CF_INT_CUSTOM_CLIENT_ID or CF_INT_CUSTOM_CLIENT_SECRET are not set.
    26  func SkipIfCustomClientCredentialsNotSet() (string, string) {
    27  	customClientID := os.Getenv("CF_INT_CUSTOM_CLIENT_ID")
    28  	customClientSecret := os.Getenv("CF_INT_CUSTOM_CLIENT_SECRET")
    29  
    30  	if customClientID == "" || customClientSecret == "" {
    31  		Skip("CF_INT_CUSTOM_CLIENT_ID or CF_INT_CUSTOM_CLIENT_SECRET is not set")
    32  	}
    33  
    34  	return customClientID, customClientSecret
    35  }
    36  
    37  func SkipIfClientCredentialsTestMode() {
    38  	if ClientCredentialsTestMode() {
    39  		Skip("CF_INT_CLIENT_CREDENTIALS_TEST_MODE is enabled")
    40  	}
    41  }
    42  
    43  func ClientCredentialsTestMode() bool {
    44  	envVar := os.Getenv("CF_INT_CLIENT_CREDENTIALS_TEST_MODE")
    45  
    46  	if envVar == "" {
    47  		return false
    48  	}
    49  
    50  	testMode, err := strconv.ParseBool(envVar)
    51  	Expect(err).ToNot(HaveOccurred(), "CF_INT_CLIENT_CREDENTIALS_TEST_MODE should be boolean")
    52  
    53  	return testMode
    54  }