Skip to content

Commit 286290d

Browse files
committed
update test
1 parent 26533f7 commit 286290d

File tree

6 files changed

+1474
-1715
lines changed

6 files changed

+1474
-1715
lines changed

internal/services/webhosting/offer_data_source.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package webhosting
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/datasource"
13+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1214
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1315
)
1416

@@ -22,11 +24,18 @@ func DataSourceOffer() *schema.Resource {
2224
Description: "Exact name of the desired offer",
2325
ConflictsWith: []string{"offer_id"},
2426
},
27+
"control_panel": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
Description: "Name of the control panel.(Cpanel or Plesk)",
31+
DiffSuppressFunc: dsf.IgnoreCase,
32+
ConflictsWith: []string{"offer_id"},
33+
},
2534
"offer_id": {
2635
Type: schema.TypeString,
2736
Optional: true,
2837
Description: "ID of the desired offer",
29-
ConflictsWith: []string{"name"},
38+
ConflictsWith: []string{"name", "control_panel"},
3039
},
3140
"billing_operation_path": {
3241
Computed: true,
@@ -187,7 +196,8 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
187196
var filteredOffer *webhosting.Offer
188197

189198
for _, offer := range res.Offers {
190-
if offer.ID == d.Get("offer_id") || offer.Name == d.Get("name") {
199+
cp, _ := d.Get("control_panel").(string)
200+
if offer.ID == d.Get("offer_id") || (offer.Name == d.Get("name") && (cp == "" || strings.EqualFold(offer.ControlPanelName, cp))) {
191201
filteredOffer = offer
192202
break
193203
}

internal/services/webhosting/offer_data_source_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ func TestAccDataSourceOffer_Basic(t *testing.T) {
2727
Check: resource.ComposeTestCheckFunc(
2828
resource.TestCheckResourceAttrSet("data.scaleway_webhosting_offer.by_id", "id"),
2929
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_id", "name", "professional"),
30-
3130
resource.TestCheckResourceAttrSet("data.scaleway_webhosting_offer.by_name", "id"),
3231
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "name", "professional"),
33-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.option", "false"),
34-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.email_accounts_quota", "10"),
35-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.email_storage_quota", "5"),
36-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.databases_quota", "-1"),
37-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.hosting_storage_quota", "100"),
38-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.support_included", "true"),
39-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.v_cpu", "4"),
40-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.ram", "2"),
41-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "price", "€ 18.99"),
32+
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "offer.0.name", "professional"),
33+
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "offer.0.price", "€ 18.99"),
4234
),
4335
},
4436
},

internal/services/webhosting/testdata/data-source-offer-basic.cassette.yaml

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

internal/services/webhosting/testdata/data-source-webhosting-basic.cassette.yaml

Lines changed: 386 additions & 533 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)