github.com/aiven/aiven-go-client@v1.36.0/aiven_go_client_suite_test.go (about)

     1  package aiven
     2  
     3  import (
     4  	"math/rand"
     5  	"os"
     6  	"strconv"
     7  	"testing"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  func TestAivenGoClient(t *testing.T) {
    15  	if os.Getenv("AIVEN_ACC") != "" {
    16  		RegisterFailHandler(Fail)
    17  		RunSpecs(t, "AivenGoClient Suite")
    18  	}
    19  }
    20  
    21  var (
    22  	client *Client
    23  )
    24  
    25  var _ = BeforeSuite(func() {
    26  	var (
    27  		err error
    28  	)
    29  
    30  	projectName := os.Getenv("AIVEN_PROJECT_NAME")
    31  	if projectName == "" {
    32  		Fail("cannot create Aiven API client, `AIVEN_PROJECT_NAME` is required")
    33  	}
    34  
    35  	client, err = SetupEnvClient("aiven-go-client/test")
    36  	if err != nil {
    37  		Fail("cannot create Aiven API client :" + err.Error())
    38  	}
    39  })
    40  
    41  var _ = Describe("Check client", func() {
    42  	Context("Create new client using username and password", func() {
    43  		It("should be valid client", func() {
    44  			Expect(client.Client).NotTo(BeNil())
    45  		})
    46  
    47  		It("should have an API token", func() {
    48  			Expect(client.APIKey).NotTo(Equal("some-random-token"))
    49  			Expect(client.APIKey).NotTo(BeEmpty())
    50  		})
    51  	})
    52  })
    53  
    54  // generateRandomString generate a random id
    55  func generateRandomID() string {
    56  	var src = rand.NewSource(time.Now().UnixNano())
    57  	return strconv.FormatInt(src.Int63(), 10)
    58  }