Skip to content

Commit 5943ae9

Browse files
ANUGRAHGDray56
andauthored
fix: List datasources throws error when list is empty (#103)
* update domains datasource * updating spaces data source * updating org quotas * updating org roles * updating space roles * updating space quotas * updating stacks datasource * updating list data sources * Rerecorded data sources tests * rerecorded space quotas fixture * Rerecorded service_route_bindings --------- Signed-off-by: Ray <debaditya.ray@sap.com> Co-authored-by: Debaditya <debadityaray00@gmail.com>
1 parent 0f275ef commit 5943ae9

File tree

58 files changed

+6437
-7584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6437
-7584
lines changed

internal/provider/datasource_apps.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,6 @@ func (d *appsDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
269269
return
270270
}
271271

272-
if len(apps) == 0 {
273-
resp.Diagnostics.AddError(
274-
"Unable to find any app in list",
275-
"No app present with mentioned criteria",
276-
)
277-
return
278-
}
279-
280272
appsList := []DatasourceAppType{}
281273
for _, app := range apps {
282274

internal/provider/datasource_apps_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package provider
22

33
import (
4-
"regexp"
54
"testing"
65

76
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -24,7 +23,7 @@ func TestAppsDataSource_Configure(t *testing.T) {
2423
space = "02c0cc92-6ecc-44b1-b7b2-096ca19ee143"
2524
}`,
2625
Check: resource.ComposeTestCheckFunc(
27-
resource.TestCheckResourceAttr(resourceName, "apps.#", "8"),
26+
resource.TestCheckResourceAttr(resourceName, "apps.#", "9"),
2827
),
2928
},
3029
{
@@ -42,6 +41,7 @@ func TestAppsDataSource_Configure(t *testing.T) {
4241
})
4342
t.Run("error path - get unavailable apps", func(t *testing.T) {
4443
cfg := getCFHomeConf()
44+
resourceName := "data.cloudfoundry_apps.apps"
4545
rec := cfg.SetupVCR(t, "fixtures/datasource_apps_invalid")
4646
defer stopQuietly(rec)
4747
resource.Test(t, resource.TestCase{
@@ -54,7 +54,9 @@ func TestAppsDataSource_Configure(t *testing.T) {
5454
space = "02c0cc92-6ecc-44b1-b7b2-096ca19ee143"
5555
name = "blah"
5656
}`,
57-
ExpectError: regexp.MustCompile(`Unable to find any app in list`),
57+
Check: resource.ComposeTestCheckFunc(
58+
resource.TestCheckResourceAttr(resourceName, "apps.#", "0"),
59+
),
5860
},
5961
},
6062
})

internal/provider/datasource_buildpacks.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ func (d *buildpacksDataSource) Read(ctx context.Context, req datasource.ReadRequ
138138
return
139139
}
140140

141-
if len(buildpacks) == 0 {
142-
resp.Diagnostics.AddError(
143-
"Unable to find any buildpack in the list",
144-
"No buildpack present with mentioned criteria",
145-
)
146-
return
147-
}
148-
149141
data.Buildpacks, diags = mapBuildpacksValuesToType(ctx, buildpacks)
150142
resp.Diagnostics.Append(diags...)
151143

internal/provider/datasource_buildpacks_test.go

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

33
import (
44
"bytes"
5-
"regexp"
65
"testing"
76
"text/template"
87

@@ -64,7 +63,9 @@ func TestBuildpacksDataSource_Configure(t *testing.T) {
6463
HclObjectName: "ds",
6564
Name: &invalidOrgGUID,
6665
}),
67-
ExpectError: regexp.MustCompile(`Unable to find any buildpack in the list`),
66+
Check: resource.ComposeAggregateTestCheckFunc(
67+
resource.TestCheckResourceAttr(resourceName, "buildpacks.#", "0"),
68+
),
6869
},
6970
},
7071
})

internal/provider/datasource_domains.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,6 @@ func (d *DomainsDataSource) Read(ctx context.Context, req datasource.ReadRequest
146146
return
147147
}
148148

149-
if len(domains) == 0 {
150-
resp.Diagnostics.AddError(
151-
"Unable to find any domain in the list",
152-
"No domain present with mentioned criteria",
153-
)
154-
return
155-
}
156-
157149
data.Domains, diags = mapDomainsValuesToType(ctx, domains)
158150
resp.Diagnostics.Append(diags...)
159151

internal/provider/datasource_isolation_segments.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ func (d *IsolationSegmentsDataSource) Read(ctx context.Context, req datasource.R
102102
return
103103
}
104104

105-
if len(isolationSegments) == 0 {
106-
resp.Diagnostics.AddError(
107-
"Unable to find any Isolation Segment in given list",
108-
"No isolation segment found with given criteria",
109-
)
110-
return
111-
}
112-
113105
data.IsolationSegments, diags = mapIsolationSegmentsValuesToType(ctx, isolationSegments)
114106
resp.Diagnostics.Append(diags...)
115107

internal/provider/datasource_isolation_segments_test.go

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

33
import (
44
"bytes"
5-
"regexp"
65
"testing"
76
"text/template"
87

@@ -85,7 +84,9 @@ func TestIsolationSegmentsDataSource_Configure(t *testing.T) {
8584
HclObjectName: "ds",
8685
Name: strtostrptr("testunavailable"),
8786
}),
88-
ExpectError: regexp.MustCompile(`Unable to find any Isolation Segment in given list`),
87+
Check: resource.ComposeAggregateTestCheckFunc(
88+
resource.TestCheckResourceAttr(resourceName, "isolation_segments.#", "0"),
89+
),
8990
},
9091
},
9192
})

internal/provider/datasource_org_quotas.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,6 @@ func (d *OrgQuotasDataSource) Read(ctx context.Context, req datasource.ReadReque
161161
)
162162
return
163163
}
164-
if len(orgQuotas) == 0 {
165-
resp.Diagnostics.AddError(
166-
"Unable to find any org quota",
167-
fmt.Sprintf("No org quota present under org %s with mentioned criteria", data.Org.ValueString()),
168-
)
169-
return
170-
}
171164

172165
data.OrgQuotas, diags = mapOrgQuotasValuesToType(orgQuotas)
173166
resp.Diagnostics.Append(diags...)

internal/provider/datasource_org_roles.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,6 @@ func (d *OrgRolesDataSource) Read(ctx context.Context, req datasource.ReadReques
154154
return
155155
}
156156

157-
if len(roles) == 0 {
158-
resp.Diagnostics.AddError(
159-
"Unable to find any roles in list",
160-
fmt.Sprintf("No roles present under org %s with mentioned criteria", data.Org.ValueString()),
161-
)
162-
return
163-
}
164-
165157
data.Roles = mapOrgRolesValuesToType(roles)
166158

167159
tflog.Trace(ctx, "read a org roles data source")

internal/provider/datasource_org_roles_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestOrgRolesDataSource_Configure(t *testing.T) {
7070
}),
7171
Check: resource.ComposeAggregateTestCheckFunc(
7272
resource.TestCheckResourceAttr(dataSourceName, "org", testOrgGuid),
73-
resource.TestCheckResourceAttr(dataSourceName, "roles.#", "2")),
73+
resource.TestCheckResourceAttr(dataSourceName, "roles.#", "5")),
7474
},
7575
{
7676
Config: hclProvider(nil) + hclOrgRolesDataSource(&OrgRolesModelPtr{
@@ -81,7 +81,7 @@ func TestOrgRolesDataSource_Configure(t *testing.T) {
8181
}),
8282
Check: resource.ComposeAggregateTestCheckFunc(
8383
resource.TestCheckResourceAttr(dataSourceName, "org", testOrgGuid),
84-
resource.TestCheckResourceAttr(dataSourceName, "roles.#", "1")),
84+
resource.TestCheckResourceAttr(dataSourceName, "roles.#", "2")),
8585
},
8686
},
8787
})

0 commit comments

Comments
 (0)