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

     1  package aiven
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  )
     7  
     8  var _ = Describe("Projects", func() {
     9  	var (
    10  		projectName  string
    11  		billingGName string
    12  		project      *Project
    13  		billingG     *BillingGroup
    14  		err          error
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		billingGName = "test-acc-bg-" + generateRandomID()
    19  		billingG, err = client.BillingGroup.Create(BillingGroupRequest{
    20  			BillingGroupName: billingGName,
    21  			Company:          ToStringPointer("testC1"),
    22  			AddressLines:     []string{"NYC Some Street 123 A"},
    23  			CountryCode:      ToStringPointer("US"),
    24  			City:             ToStringPointer("NY"),
    25  			ZipCode:          ToStringPointer("101778"),
    26  			BillingCurrency:  ToStringPointer("EUR"),
    27  		})
    28  
    29  		projectName = "test-acc-pr" + generateRandomID()
    30  		project, err = client.Projects.Create(CreateProjectRequest{
    31  			Project:                      projectName,
    32  			BillingCurrency:              "EUR",
    33  			TechnicalEmails:              ContactEmailFromStringSlice([]string{"test@example.com"}),
    34  			UseSourceProjectBillingGroup: false,
    35  			BillingGroupId:               billingG.Id,
    36  			Tags:                         map[string]string{},
    37  		})
    38  	})
    39  
    40  	Context("Create new project", func() {
    41  		It("should not error", func() {
    42  			if !IsAlreadyExists(err) {
    43  				Expect(err).NotTo(HaveOccurred())
    44  			}
    45  		})
    46  
    47  		It("should populate fields properly", func() {
    48  			project, err = client.Projects.Get(projectName)
    49  			Expect(err).NotTo(HaveOccurred())
    50  			Expect(project).NotTo(BeNil())
    51  
    52  			if project != nil {
    53  				Expect(project.Name).NotTo(BeEmpty())
    54  				Expect(project.AccountId).To(BeEmpty())
    55  				Expect(project.BillingCurrency).NotTo(BeEmpty())
    56  				Expect(project.GetTechnicalEmailsAsStringSlice()).NotTo(BeEmpty())
    57  				Expect(project.BillingGroupId).NotTo(BeEmpty())
    58  				Expect(project.BillingGroupName).Should(Equal(billingGName))
    59  			}
    60  		})
    61  
    62  		It("update project name", func() {
    63  			project, err = client.Projects.Update(projectName, UpdateProjectRequest{
    64  				Name: projectName + "-new",
    65  				Tags: map[string]string{},
    66  			})
    67  
    68  			if err == nil {
    69  				projectName = projectName + "-new"
    70  			}
    71  
    72  			Expect(err).NotTo(HaveOccurred())
    73  			Expect(project).NotTo(BeNil())
    74  		})
    75  	})
    76  
    77  	Context("Get project event logs", func() {
    78  		It("should be event logs", func() {
    79  			events, logErr := client.Projects.GetEventLog(projectName)
    80  			Expect(logErr).To(BeNil())
    81  			Expect(events).ToNot(BeNil())
    82  			Expect(events).Should(Not(BeEmpty()))
    83  			for _, event := range events {
    84  				Expect(event).NotTo(BeNil())
    85  			}
    86  		})
    87  	})
    88  
    89  	Context("Get service types", func() {
    90  		It("check returned service types", func() {
    91  			serviceTypes, err := client.Projects.ServiceTypes(projectName)
    92  			Expect(err).To(BeNil())
    93  			Expect(serviceTypes).ToNot(BeNil())
    94  			Expect(serviceTypes).Should(Not(BeEmpty()))
    95  			for _, serviceType := range serviceTypes {
    96  				Expect(serviceType).NotTo(BeNil())
    97  			}
    98  		})
    99  	})
   100  
   101  	Context("Get integration types", func() {
   102  		It("check returned integration types", func() {
   103  			integrationTypes, err := client.Projects.IntegrationTypes(projectName)
   104  			Expect(err).To(BeNil())
   105  			Expect(integrationTypes).ToNot(BeNil())
   106  			Expect(integrationTypes).Should(Not(BeEmpty()))
   107  			for _, integrationType := range integrationTypes {
   108  				Expect(integrationType).NotTo(BeNil())
   109  			}
   110  		})
   111  	})
   112  
   113  	Context("Get integration endpoint types", func() {
   114  		It("check returned integration endpoint types", func() {
   115  			endpointTypes, err := client.Projects.IntegrationEndpointTypes(projectName)
   116  			Expect(err).To(BeNil())
   117  			Expect(endpointTypes).ToNot(BeNil())
   118  			Expect(endpointTypes).Should(Not(BeEmpty()))
   119  			for _, endpointType := range endpointTypes {
   120  				Expect(endpointType).NotTo(BeNil())
   121  			}
   122  		})
   123  	})
   124  
   125  	AfterEach(func() {
   126  		err = client.Projects.Delete(projectName)
   127  		if err != nil {
   128  			Fail("cannot delete project : " + err.Error())
   129  		}
   130  
   131  		err = client.BillingGroup.Delete(billingG.Id)
   132  		if err != nil {
   133  			Fail("cannot delete billing group : " + err.Error())
   134  		}
   135  	})
   136  })