Skip to content

Commit ea34989

Browse files
committed
wip
1 parent 4f2315f commit ea34989

File tree

11 files changed

+31
-55
lines changed

11 files changed

+31
-55
lines changed

internal/acctest/acctest.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/google/uuid"
1110
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1211
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1312
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
@@ -43,6 +42,7 @@ func NewTestTools(t *testing.T) *TestTools {
4342
ProviderSchema: nil,
4443
TerraformVersion: "terraform-tests",
4544
HTTPClient: httpClient,
45+
ForceProjectID: "00000000-0000-0000-0000-000000000000",
4646
})
4747
require.NoError(t, err)
4848

@@ -63,7 +63,11 @@ func NewTestTools(t *testing.T) *TestTools {
6363
}
6464
}
6565

66-
func NewTestToolsWithoutRequestProjectID(t *testing.T) *TestTools {
66+
/*
67+
Resources that depends on a projectID should use this function instead of NewTestTools
68+
It will use a specific matcher that strip the project_id from the query to match the query of the recorded cassette
69+
*/
70+
func NewTestToolsWithoutDefaultProjectID(t *testing.T) *TestTools {
6771
t.Helper()
6872

6973
ctx := t.Context()
@@ -73,17 +77,14 @@ func NewTestToolsWithoutRequestProjectID(t *testing.T) *TestTools {
7377
t.Fatalf("cannot detect working directory for testing")
7478
}
7579

76-
// Create a http client with recording capabilities
7780
httpClient, cleanup, err := getHTTPRecoder(t, folder, *UpdateCassettes, cassetteMatcherWithoutProjectID)
7881
require.NoError(t, err)
7982

80-
// Create meta that will be passed in the provider config
8183
m, err := meta.NewMeta(ctx, &meta.Config{
8284
ProviderSchema: nil,
8385
TerraformVersion: "terraform-tests",
8486
HTTPClient: httpClient,
85-
// avoid "Error: could not detect project id" in CI
86-
ForceProjectID: uuid.New().String(),
87+
ForceProjectID: "00000000-0000-0000-0000-000000000000",
8788
})
8889
require.NoError(t, err)
8990

internal/acctest/vcr.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
235235
cassetteBodyMatcher(actual, expected)
236236
}
237237

238-
// cassetteMatcherWithoutProjectID is a custom matcher that check equivalence of a played request against a recorded one
239-
// It compares method, path and query but will remove unwanted values from query
238+
// cassetteMatcherWithoutProjectID strip the project_id from the query to match the query of the recorded cassette
240239
func cassetteMatcherWithoutProjectID(actual *http.Request, expected cassette.Request) bool {
241240
expectedURL, _ := url.Parse(expected.URL)
242241
actualURL := actual.URL

internal/services/account/project_data_source_test.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const dummyOrgID = "AB7BD9BF-E1BD-41E8-9F1D-F16A2E3F3925"
1212

1313
func TestAccDataSourceProject_Basic(t *testing.T) {
14-
tt := acctest.NewTestTools(t)
14+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1515
defer tt.Cleanup()
1616

1717
orgID, orgIDExists := tt.Meta.ScwClient().GetDefaultOrganizationID()
@@ -52,7 +52,7 @@ func TestAccDataSourceProject_Basic(t *testing.T) {
5252
}
5353

5454
func TestAccDataSourceProject_Default(t *testing.T) {
55-
tt := acctest.NewTestTools(t)
55+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
5656
defer tt.Cleanup()
5757

5858
orgID, orgIDExists := tt.Meta.ScwClient().GetDefaultOrganizationID()
@@ -95,32 +95,8 @@ func TestAccDataSourceProject_Default(t *testing.T) {
9595
})
9696
}
9797

98-
func TestAccDataSourceProject_Extract(t *testing.T) {
99-
tt := acctest.NewTestTools(t)
100-
defer tt.Cleanup()
101-
102-
projectID, projectIDExists := tt.Meta.ScwClient().GetDefaultProjectID()
103-
if !projectIDExists {
104-
t.Skip("no default project ID")
105-
}
106-
107-
resource.ParallelTest(t, resource.TestCase{
108-
PreCheck: func() { acctest.PreCheck(t) },
109-
ProviderFactories: tt.ProviderFactories,
110-
Steps: []resource.TestStep{
111-
{
112-
Config: `data scaleway_account_project "project" {}`,
113-
Check: resource.ComposeTestCheckFunc(
114-
resource.TestCheckResourceAttr("data.scaleway_account_project.project", "id", projectID),
115-
resource.TestCheckResourceAttrSet("data.scaleway_account_project.project", "name"),
116-
),
117-
},
118-
},
119-
})
120-
}
121-
12298
func TestAccDataSourceProject_List(t *testing.T) {
123-
tt := acctest.NewTestTools(t)
99+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
124100
defer tt.Cleanup()
125101

126102
orgID, orgIDExists := tt.Meta.ScwClient().GetDefaultOrganizationID()

internal/services/container/container_data_source_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestAccDataSourceContainer_Basic(t *testing.T) {
11-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
11+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1212
defer tt.Cleanup()
1313

1414
resource.ParallelTest(t, resource.TestCase{
@@ -51,7 +51,7 @@ func TestAccDataSourceContainer_Basic(t *testing.T) {
5151
}
5252

5353
func TestAccDataSourceContainer_HealthCheck(t *testing.T) {
54-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
54+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
5555
defer tt.Cleanup()
5656

5757
resource.ParallelTest(t, resource.TestCase{
@@ -89,7 +89,7 @@ func TestAccDataSourceContainer_HealthCheck(t *testing.T) {
8989
}
9090

9191
func TestAccDataSourceContainer_ScalingOption(t *testing.T) {
92-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
92+
tt := acctest.NewTestTools(t)
9393
defer tt.Cleanup()
9494
resource.ParallelTest(t, resource.TestCase{
9595
PreCheck: func() { acctest.PreCheck(t) },

internal/services/container/container_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestAccContainer_Basic(t *testing.T) {
18-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
18+
tt := acctest.NewTestTools(t)
1919
defer tt.Cleanup()
2020
resource.ParallelTest(t, resource.TestCase{
2121
PreCheck: func() { acctest.PreCheck(t) },
@@ -124,7 +124,7 @@ func TestAccContainer_Basic(t *testing.T) {
124124
}
125125

126126
func TestAccContainer_Env(t *testing.T) {
127-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
127+
tt := acctest.NewTestTools(t)
128128
defer tt.Cleanup()
129129
resource.ParallelTest(t, resource.TestCase{
130130
PreCheck: func() { acctest.PreCheck(t) },
@@ -208,7 +208,7 @@ func TestAccContainer_Env(t *testing.T) {
208208
}
209209

210210
func TestAccContainer_WithIMG(t *testing.T) {
211-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
211+
tt := acctest.NewTestTools(t)
212212
defer tt.Cleanup()
213213

214214
containerNamespace := "test-cr-ns-02"
@@ -267,7 +267,7 @@ func TestAccContainer_WithIMG(t *testing.T) {
267267
}
268268

269269
func TestAccContainer_HTTPOption(t *testing.T) {
270-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
270+
tt := acctest.NewTestTools(t)
271271
defer tt.Cleanup()
272272
resource.ParallelTest(t, resource.TestCase{
273273
PreCheck: func() { acctest.PreCheck(t) },
@@ -323,7 +323,7 @@ func TestAccContainer_HTTPOption(t *testing.T) {
323323
}
324324

325325
func TestAccContainer_Sandbox(t *testing.T) {
326-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
326+
tt := acctest.NewTestTools(t)
327327
defer tt.Cleanup()
328328
resource.ParallelTest(t, resource.TestCase{
329329
PreCheck: func() { acctest.PreCheck(t) },
@@ -393,7 +393,7 @@ func TestAccContainer_Sandbox(t *testing.T) {
393393
}
394394

395395
func TestAccContainer_HealthCheck(t *testing.T) {
396-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
396+
tt := acctest.NewTestTools(t)
397397
defer tt.Cleanup()
398398
resource.ParallelTest(t, resource.TestCase{
399399
PreCheck: func() { acctest.PreCheck(t) },
@@ -447,7 +447,7 @@ func TestAccContainer_HealthCheck(t *testing.T) {
447447
}
448448

449449
func TestAccContainer_ScalingOption(t *testing.T) {
450-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
450+
tt := acctest.NewTestTools(t)
451451
defer tt.Cleanup()
452452
resource.ParallelTest(t, resource.TestCase{
453453
PreCheck: func() { acctest.PreCheck(t) },

internal/services/container/cron_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestAccCron_Basic(t *testing.T) {
16-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
16+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1717
defer tt.Cleanup()
1818

1919
resource.ParallelTest(t, resource.TestCase{
@@ -76,7 +76,7 @@ func TestAccCron_Basic(t *testing.T) {
7676
}
7777

7878
func TestAccCron_WithMultiArgs(t *testing.T) {
79-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
79+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
8080
defer tt.Cleanup()
8181

8282
resource.ParallelTest(t, resource.TestCase{

internal/services/container/domain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestAccDomain_Basic(t *testing.T) {
18-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
18+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1919
defer tt.Cleanup()
2020

2121
testDNSZone := "container-basic." + acctest.TestDomain

internal/services/container/namespace_data_source_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestAccDataSourceNamespace_Basic(t *testing.T) {
11-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
11+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1212
defer tt.Cleanup()
1313

1414
resource.ParallelTest(t, resource.TestCase{

internal/services/container/namespace_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
const containerNamespaceResource = "scaleway_container_namespace"
1818

1919
func TestAccNamespace_Basic(t *testing.T) {
20-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
20+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
2121
defer tt.Cleanup()
2222

2323
resource.ParallelTest(t, resource.TestCase{
@@ -175,7 +175,7 @@ func TestAccNamespace_Basic(t *testing.T) {
175175
}
176176

177177
func TestAccNamespace_SecretManagement(t *testing.T) {
178-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
178+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
179179
defer tt.Cleanup()
180180

181181
resource.ParallelTest(t, resource.TestCase{
@@ -237,7 +237,7 @@ func TestAccNamespace_SecretManagement(t *testing.T) {
237237
}
238238

239239
func TestAccNamespace_DestroyRegistry(t *testing.T) {
240-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
240+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
241241
defer tt.Cleanup()
242242

243243
resource.ParallelTest(t, resource.TestCase{

internal/services/container/token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestAccToken_Basic(t *testing.T) {
17-
tt := acctest.NewTestToolsWithoutRequestProjectID(t)
17+
tt := acctest.NewTestToolsWithoutDefaultProjectID(t)
1818
defer tt.Cleanup()
1919

2020
expiresAt := time.Now().Add(time.Hour * 24).Format(time.RFC3339)

0 commit comments

Comments
 (0)