...
1 package project
2
3 import (
4 "context"
5 "os"
6 "testing"
7
8 "github.com/stretchr/testify/suite"
9 cb "google.golang.org/api/cloudbilling/v1"
10 crm "google.golang.org/api/cloudresourcemanager/v1"
11
12 "edge-infra.dev/test/framework"
13 "edge-infra.dev/test/framework/gcp"
14 "edge-infra.dev/test/framework/integration"
15 )
16
17 func TestMain(m *testing.M) {
18 framework.HandleFlags()
19
20 gcp.Defaults()
21 os.Exit(m.Run())
22 }
23
24 type Suite struct {
25 *framework.Framework
26 projectID string
27 folderID string
28 billingAccount string
29 ctx context.Context
30 cloudresource *crm.Service
31 cloudbilling *cb.APIService
32 }
33
34 func TestProjectIntegration(t *testing.T) {
35 f := framework.New("gcp-proj").
36 Setup(
37 integration.SkipIfNot,
38 gcp.NeedsProjectID,
39 gcp.NeedsFolderID,
40 gcp.NeedsBillingAccount,
41 )
42
43 s := &Suite{
44 Framework: f,
45 projectID: gcp.GCloud.ProjectID,
46 folderID: gcp.GCloud.FolderID,
47 billingAccount: gcp.GCloud.BillingAccount,
48 ctx: context.Background(),
49 }
50 f.BeforeEachTest(s.beforeEach)
51
52 suite.Run(t, s)
53 }
54
55 func (s *Suite) TestProjectCreationWithBillingAccount() {
56 name := s.UniqueName
57 s.Log(name)
58 prj, err := CreateWithBillingAccount(s.cloudresource, s.cloudbilling, name, s.folderID, s.billingAccount)
59 s.NoError(err)
60 s.NoError(DeleteProject(s.cloudresource, prj.ProjectId))
61 s.Equal(name, prj.Name, "provided name was not the same as created project name")
62 }
63
64 func (s *Suite) beforeEach(_ *framework.Framework) {
65 cloudresource, err := crm.NewService(s.ctx)
66 if err != nil {
67 s.FailNow("failed to create cloud resource manager service", err)
68 }
69 s.cloudresource = cloudresource
70 cloudbilling, err := cb.NewService(s.ctx)
71 if err != nil {
72 s.FailNow("failed to create cloud billing service", err)
73 }
74 s.cloudbilling = cloudbilling
75 }
76
View as plain text