Skip to content

Commit 66053ec

Browse files
fix account project tests, switch account tests to VCRv4 (#3463)
1 parent ad0af5e commit 66053ec

8 files changed

+2046
-3730
lines changed

internal/acctest/acctest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type TestTools struct {
3232
}
3333

3434
var foldersUsingVCRv4 = []string{
35+
"account",
3536
"container",
3637
"instance",
3738
"k8s",

internal/services/account/project_data_source_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package account_test
22

33
import (
44
"fmt"
5+
"strconv"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -125,6 +126,11 @@ func TestAccDataSourceProject_List(t *testing.T) {
125126
orgID = dummyOrgID
126127
}
127128

129+
projectID, projectIDExists := tt.Meta.ScwClient().GetDefaultProjectID()
130+
if !projectIDExists {
131+
t.Skip("no default project ID")
132+
}
133+
128134
resource.ParallelTest(t, resource.TestCase{
129135
ProtoV6ProviderFactories: tt.ProviderFactories,
130136
CheckDestroy: resource.ComposeTestCheckFunc(
@@ -137,11 +143,21 @@ func TestAccDataSourceProject_List(t *testing.T) {
137143
organization_id = "%s"
138144
}`, orgID),
139145
Check: resource.ComposeTestCheckFunc(
140-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.#", "8"),
141-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.id", "6867048b-fe12-4e96-835e-41c79a39604b"),
142-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.1.id", "8cc8dd4d-a094-407a-89a3-9d004674e936"),
146+
resource.TestCheckResourceAttrSet("data.scaleway_account_projects.projects", "projects.#"),
147+
resource.TestCheckResourceAttrWith("data.scaleway_account_projects.projects", "projects.#", func(value string) error {
148+
count, err := strconv.Atoi(value)
149+
if err != nil {
150+
return err
151+
}
152+
153+
if count < 1 {
154+
return fmt.Errorf("expected at least one project, got %d", count)
155+
}
156+
157+
return nil
158+
}),
159+
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.id", projectID),
143160
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.name", "default"),
144-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.1.name", "tf_tests_container_trigger_sqs"),
145161
),
146162
},
147163
},

0 commit comments

Comments
 (0)