Skip to content

Commit 5b069b6

Browse files
authored
chore: Replace fwtypes.JSONStringType with jsontypes.NormalizedType (#3452)
* use JSON custom type * fix linter
1 parent c5e3f83 commit 5b069b6

File tree

5 files changed

+19
-159
lines changed

5 files changed

+19
-159
lines changed

internal/common/fwtypes/json_string.go

Lines changed: 0 additions & 141 deletions
This file was deleted.

internal/service/streamprocessor/model.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"context"
55
"encoding/json"
66

7+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
78
"github.com/hashicorp/terraform-plugin-framework/diag"
89
"github.com/hashicorp/terraform-plugin-framework/types"
910
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
10-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/fwtypes"
1111
"go.mongodb.org/atlas-sdk/v20250312004/admin"
1212
)
1313

@@ -172,12 +172,12 @@ func convertDlqToTF(ctx context.Context, dlq *admin.StreamsDLQ) (*types.Object,
172172
}
173173
return &dlqObject, nil
174174
}
175-
func convertPipelineToTF(pipeline []any) (fwtypes.JSONString, diag.Diagnostics) {
175+
func convertPipelineToTF(pipeline []any) (jsontypes.Normalized, diag.Diagnostics) {
176176
pipelineJSON, err := json.Marshal(pipeline)
177177
if err != nil {
178-
return fwtypes.JSONStringValue(""), diag.Diagnostics{diag.NewErrorDiagnostic("failed to marshal pipeline", err.Error())}
178+
return jsontypes.NewNormalizedValue(""), diag.Diagnostics{diag.NewErrorDiagnostic("failed to marshal pipeline", err.Error())}
179179
}
180-
return fwtypes.JSONStringValue(string(pipelineJSON)), nil
180+
return jsontypes.NewNormalizedValue(string(pipelineJSON)), nil
181181
}
182182

183183
func convertStatsToTF(stats any) (types.String, diag.Diagnostics) {

internal/service/streamprocessor/model_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"encoding/json"
55
"testing"
66

7+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
78
"github.com/hashicorp/terraform-plugin-framework/types"
89
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
9-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/fwtypes"
1010
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/schemafunc"
1111
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streamprocessor"
1212
"github.com/stretchr/testify/assert"
@@ -190,7 +190,7 @@ func TestSDKToTFModel(t *testing.T) {
190190
InstanceName: types.StringValue(instanceName),
191191
Options: types.ObjectNull(streamprocessor.OptionsObjectType.AttrTypes),
192192
ProcessorID: types.StringValue(processorID),
193-
Pipeline: fwtypes.JSONStringValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
193+
Pipeline: jsontypes.NewNormalizedValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
194194
ProcessorName: types.StringValue(processorName),
195195
ProjectID: types.StringValue(projectID),
196196
State: types.StringValue("CREATED"),
@@ -204,7 +204,7 @@ func TestSDKToTFModel(t *testing.T) {
204204
InstanceName: types.StringValue(instanceName),
205205
Options: types.ObjectNull(streamprocessor.OptionsObjectType.AttrTypes),
206206
ProcessorID: types.StringValue(processorID),
207-
Pipeline: fwtypes.JSONStringValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
207+
Pipeline: jsontypes.NewNormalizedValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
208208
ProcessorName: types.StringValue(processorName),
209209
ProjectID: types.StringValue(projectID),
210210
State: types.StringValue("STARTED"),
@@ -218,7 +218,7 @@ func TestSDKToTFModel(t *testing.T) {
218218
InstanceName: types.StringValue(instanceName),
219219
Options: optionsToTFModel(t, &streamOptionsExample),
220220
ProcessorID: types.StringValue(processorID),
221-
Pipeline: fwtypes.JSONStringValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
221+
Pipeline: jsontypes.NewNormalizedValue("[{\"$source\":{\"connectionName\":\"sample_stream_solar\"}},{\"$emit\":{\"connectionName\":\"__testLog\"}}]"),
222222
ProcessorName: types.StringValue(processorName),
223223
ProjectID: types.StringValue(projectID),
224224
State: types.StringValue("STARTED"),

internal/service/streamprocessor/resource_schema.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package streamprocessor
33
import (
44
"context"
55

6+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
67
"github.com/hashicorp/terraform-plugin-framework/attr"
78
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
89
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1011
"github.com/hashicorp/terraform-plugin-framework/types"
11-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/fwtypes"
1212
)
1313

1414
func ResourceSchema(ctx context.Context) schema.Schema {
@@ -26,7 +26,7 @@ func ResourceSchema(ctx context.Context) schema.Schema {
2626
MarkdownDescription: "Human-readable label that identifies the stream instance.",
2727
},
2828
"pipeline": schema.StringAttribute{
29-
CustomType: fwtypes.JSONStringType,
29+
CustomType: jsontypes.NormalizedType{},
3030
Required: true,
3131
MarkdownDescription: "Stream aggregation pipeline you want to apply to your streaming data. [MongoDB Atlas Docs](https://www.mongodb.com/docs/atlas/atlas-stream-processing/stream-aggregation/#std-label-stream-aggregation)" +
3232
" contain more information. Using [jsonencode](https://developer.hashicorp.com/terraform/language/functions/jsonencode) is recommended when setting this attribute. For more details see the [Aggregation Pipelines Documentation](https://www.mongodb.com/docs/atlas/atlas-stream-processing/stream-aggregation/)",
@@ -78,14 +78,14 @@ func ResourceSchema(ctx context.Context) schema.Schema {
7878
}
7979

8080
type TFStreamProcessorRSModel struct {
81-
InstanceName types.String `tfsdk:"instance_name"`
82-
Options types.Object `tfsdk:"options"`
83-
Pipeline fwtypes.JSONString `tfsdk:"pipeline"`
84-
ProcessorID types.String `tfsdk:"id"`
85-
ProcessorName types.String `tfsdk:"processor_name"`
86-
ProjectID types.String `tfsdk:"project_id"`
87-
State types.String `tfsdk:"state"`
88-
Stats types.String `tfsdk:"stats"`
81+
InstanceName types.String `tfsdk:"instance_name"`
82+
Options types.Object `tfsdk:"options"`
83+
Pipeline jsontypes.Normalized `tfsdk:"pipeline"`
84+
ProcessorID types.String `tfsdk:"id"`
85+
ProcessorName types.String `tfsdk:"processor_name"`
86+
ProjectID types.String `tfsdk:"project_id"`
87+
State types.String `tfsdk:"state"`
88+
Stats types.String `tfsdk:"stats"`
8989
}
9090

9191
type TFOptionsModel struct {

internal/testutil/unit/http_mocker_round_tripper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func (r *MockRoundTripper) nextDiffResponseIndex() {
131131
step := r.currentStep()
132132
if step == nil {
133133
r.t.Fatal("no more steps, in testCase")
134+
return
134135
}
135136
for index, req := range step.DiffRequests {
136137
if _, ok := r.foundsDiffs[index]; !ok {

0 commit comments

Comments
 (0)