Skip to content

Commit 8438d9b

Browse files
authored
clusterEmail Datasource fixed (#282)
* clusterEmail Datasource fixed * added a test
1 parent 6ff8e76 commit 8438d9b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

powerscale/provider/cluster_email_datasource.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ package provider
1919

2020
import (
2121
"context"
22+
powerscale "dell/powerscale-go-client"
2223
"fmt"
23-
"github.com/hashicorp/terraform-plugin-framework/datasource"
24-
"github.com/hashicorp/terraform-plugin-framework/types"
2524
"terraform-provider-powerscale/client"
2625
"terraform-provider-powerscale/powerscale/constants"
2726
"terraform-provider-powerscale/powerscale/helper"
2827
"terraform-provider-powerscale/powerscale/models"
2928

29+
"github.com/hashicorp/terraform-plugin-framework/datasource"
30+
"github.com/hashicorp/terraform-plugin-framework/types"
31+
3032
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
3133
"github.com/hashicorp/terraform-plugin-log/tflog"
3234
)
@@ -156,7 +158,23 @@ func (d *ClusterEmailDataSource) Read(ctx context.Context, req datasource.ReadRe
156158
return
157159
}
158160

159-
clusterEmail, err := helper.GetClusterEmail(ctx, d.client)
161+
clusterVersion, err := helper.GetClusterVersion(ctx, d.client)
162+
if err != nil {
163+
errStr := constants.ReadClusterErrorMsg + "with error: "
164+
message := helper.GetErrorString(err, errStr)
165+
resp.Diagnostics.AddError(
166+
"Error reading cluster version",
167+
message,
168+
)
169+
return
170+
}
171+
172+
var clusterEmail *powerscale.V1ClusterEmail
173+
if clusterVersion == "9.10.0.0" {
174+
clusterEmail, err = helper.GetV21ClusterEmail(ctx, d.client)
175+
} else {
176+
clusterEmail, err = helper.GetClusterEmail(ctx, d.client)
177+
}
160178
if err != nil {
161179
errStr := constants.ReadClusterEmailSettingsErrorMsg + "with error: "
162180
message := helper.GetErrorString(err, errStr)

powerscale/provider/cluster_email_datasource_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func TestAccClusterEmailDatasourceErrorGetAll(t *testing.T) {
6262
Config: ProviderConfig + clusterEmailDataSourceConfig,
6363
ExpectError: regexp.MustCompile("mock error"),
6464
},
65+
{
66+
PreConfig: func() {
67+
FunctionMocker = Mock(helper.GetClusterVersion).Return("", fmt.Errorf("mock error")).Build()
68+
},
69+
Config: ProviderConfig + clusterEmailDataSourceConfig,
70+
ExpectError: regexp.MustCompile("mock error"),
71+
},
6572
},
6673
})
6774
}

0 commit comments

Comments
 (0)