From 194dde1db6bec67f8c4c82273071a4c73729c41d Mon Sep 17 00:00:00 2001 From: Ryan Parman Date: Thu, 19 Oct 2023 19:12:13 -0600 Subject: [PATCH] feat: Implemented support for `str_iterative_replace`. (#31) * feat: str_iterative_replace. * refactor: Implemented a new type. Refactored all other code to match. --- .golangci.yml | 1 + bats/str_iterative_replace.bats.sh | 12 ++ bats/tfschema_listing.bats.sh | 10 +- corefunc/env_ensure.go | 5 +- corefunc/str_iterative_replace.go | 44 +++++ corefunc/str_iterative_replace_test.go | 100 ++++++++++ corefunc/truncate_label.go | 6 +- corefunc/types/str_iterative_replace_map.go | 21 ++ corefuncprovider/provider.go | 1 + .../str_iterative_replace_data_source.go | 186 ++++++++++++++++++ ...terative_replace_data_source_fixture.tftpl | 12 ++ .../str_iterative_replace_data_source_test.go | 67 +++++++ docs/data-sources/str_iterative_replace.md | 78 ++++++++ .../data-source.tf | 30 +++ .../versions.tftpl | 13 ++ testfixtures/str_iterative_replace.go | 39 ++++ 16 files changed, 615 insertions(+), 10 deletions(-) create mode 100644 bats/str_iterative_replace.bats.sh create mode 100644 corefunc/str_iterative_replace.go create mode 100644 corefunc/str_iterative_replace_test.go create mode 100644 corefunc/types/str_iterative_replace_map.go create mode 100644 corefuncprovider/str_iterative_replace_data_source.go create mode 100644 corefuncprovider/str_iterative_replace_data_source_fixture.tftpl create mode 100644 corefuncprovider/str_iterative_replace_data_source_test.go create mode 100644 docs/data-sources/str_iterative_replace.md create mode 100644 examples/data-sources/corefunc_str_iterative_replace/data-source.tf create mode 100644 examples/data-sources/corefunc_str_iterative_replace/versions.tftpl create mode 100644 testfixtures/str_iterative_replace.go diff --git a/.golangci.yml b/.golangci.yml index 52be3e26..a27b6a42 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -837,6 +837,7 @@ issues: - linters: - tagliatelle + - gofumpt source: lint:allow_format - text: (is unused) diff --git a/bats/str_iterative_replace.bats.sh b/bats/str_iterative_replace.bats.sh new file mode 100644 index 00000000..6ed8e24f --- /dev/null +++ b/bats/str_iterative_replace.bats.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bats +# https://bats-core.readthedocs.io/en/stable/writing-tests.html + +@test "corefunc_str_iterative_replace: attrs" { + run bash -c "tfschema data show -format=json corefunc_str_iterative_replace | jq -Mrc '.attributes[]'" + + [ "$status" -eq 0 ] + [[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]] + [[ ${lines[1]} == '{"name":"replacements","type":"list(object({new=string,old=string}))","required":true,"optional":false,"computed":false,"sensitive":false}' ]] + [[ ${lines[2]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]] + [[ ${lines[3]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]] +} diff --git a/bats/tfschema_listing.bats.sh b/bats/tfschema_listing.bats.sh index 532a6774..c4a19ffd 100644 --- a/bats/tfschema_listing.bats.sh +++ b/bats/tfschema_listing.bats.sh @@ -8,9 +8,9 @@ [[ ${lines[0]} == "corefunc_env_ensure" ]] [[ ${lines[1]} == "corefunc_str_camel" ]] [[ ${lines[2]} == "corefunc_str_constant" ]] - [[ ${lines[3]} == "corefunc_str_kebab" ]] - [[ ${lines[4]} == "corefunc_str_pascal" ]] - [[ ${lines[5]} == "corefunc_str_snake" ]] - [[ ${lines[6]} == "corefunc_str_truncate_label" ]] - + [[ ${lines[3]} == "corefunc_str_iterative_replace" ]] + [[ ${lines[4]} == "corefunc_str_kebab" ]] + [[ ${lines[5]} == "corefunc_str_pascal" ]] + [[ ${lines[6]} == "corefunc_str_snake" ]] + [[ ${lines[7]} == "corefunc_str_truncate_label" ]] } diff --git a/corefunc/env_ensure.go b/corefunc/env_ensure.go index 6017d851..67b4ec57 100644 --- a/corefunc/env_ensure.go +++ b/corefunc/env_ensure.go @@ -32,9 +32,10 @@ variable is not set, or if its value doesn't match the expected patttern. ---- -* name (string): The name of the environment variable to check. + - name (string): The name of the environment variable to check. -* pattern (*regexp.Regexp): The result of a call to `regexp.Compile()` or `regexp.MustCompile()`. + - pattern (*regexp.Regexp): The result of a call to `regexp.Compile()` or + `regexp.MustCompile()`. */ func EnvEnsure(name string, pattern ...*regexp.Regexp) error { if os.Getenv(name) == "" { diff --git a/corefunc/str_iterative_replace.go b/corefunc/str_iterative_replace.go new file mode 100644 index 00000000..7e26ddc0 --- /dev/null +++ b/corefunc/str_iterative_replace.go @@ -0,0 +1,44 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package corefunc + +import ( + "strings" + + "github.com/northwood-labs/terraform-provider-corefunc/corefunc/types" +) + +/* +StrIterativeReplace iterates over a list of replacements. This allows you to +accept a list of replacements of unknown length from users, and apply them all +in sequence. It is a wrapper around `strings.ReplaceAll()`. + +---- + + - str (string): The string to which we apply the replacements. + + - replacements ([]types.Replacement): A list of replacements to apply to + the string, in sequence. +*/ +func StrIterativeReplace(str string, replacements []types.Replacement) string { + s := str + + for i := range replacements { + replacement := replacements[i] + s = strings.ReplaceAll(s, replacement.Old, replacement.New) + } + + return s +} diff --git a/corefunc/str_iterative_replace_test.go b/corefunc/str_iterative_replace_test.go new file mode 100644 index 00000000..028c9ccc --- /dev/null +++ b/corefunc/str_iterative_replace_test.go @@ -0,0 +1,100 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package corefunc + +import ( + "fmt" + "testing" + + "github.com/northwood-labs/terraform-provider-corefunc/corefunc/types" + "github.com/northwood-labs/terraform-provider-corefunc/testfixtures" +) + +func ExampleStrIterativeReplace() { + output := StrIterativeReplace( + "This is a string for testing replacements. New Relic. Set-up.", + []types.Replacement{ + {Old: ".", New: ""}, + {Old: " ", New: "_"}, + {Old: "-", New: "_"}, + {Old: "New_Relic", New: "datadog"}, + {Old: "This", New: "this"}, + {Old: "Set_up", New: "setup"}, + }, + ) + + fmt.Println(output) + + // Output: + // this_is_a_string_for_testing_replacements_datadog_setup +} + +func TestStrIterativeReplace(t *testing.T) { + for name, tc := range testfixtures.StrIterativeReplaceTestTable { + t.Run(name, func(t *testing.T) { + output := StrIterativeReplace(tc.Input, tc.Replacements) + + if output != tc.Expected { + t.Errorf("Expected %s, got %s", tc.Expected, output) + } + }) + } +} + +func BenchmarkStrIterativeReplace(b *testing.B) { + b.ReportAllocs() + for name, tc := range testfixtures.StrIterativeReplaceTestTable { + b.Run(name, func(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = StrIterativeReplace(tc.Input, tc.Replacements) + } + }) + } +} + +func BenchmarkStrIterativeReplaceParallel(b *testing.B) { + b.ReportAllocs() + for name, tc := range testfixtures.StrIterativeReplaceTestTable { + b.Run(name, func(b *testing.B) { + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _ = StrIterativeReplace(tc.Input, tc.Replacements) + } + }) + }) + } +} + +func FuzzStrIterativeReplace(f *testing.F) { + for _, tc := range testfixtures.StrIterativeReplaceTestTable { + f.Add(tc.Input) + f.Add(tc.Expected) + + for _, r := range tc.Replacements { + f.Add(r.Old) + f.Add(r.New) + } + } + + f.Fuzz( + func(t *testing.T, in string) { + _ = StrIterativeReplace(in, []types.Replacement{ + {Old: in, New: in}, + }) + }, + ) +} diff --git a/corefunc/truncate_label.go b/corefunc/truncate_label.go index 76a83f15..2bb2f4fe 100644 --- a/corefunc/truncate_label.go +++ b/corefunc/truncate_label.go @@ -30,11 +30,11 @@ string. ---- -* maxLength (int64): The maximum allowed length of the combined label. + - maxLength (int64): The maximum allowed length of the combined label. -* prefix (string): The prefix to prepend to the label. + - prefix (string): The prefix to prepend to the label. -* label (string): The label itself. + - label (string): The label itself. ---- diff --git a/corefunc/types/str_iterative_replace_map.go b/corefunc/types/str_iterative_replace_map.go new file mode 100644 index 00000000..43269e19 --- /dev/null +++ b/corefunc/types/str_iterative_replace_map.go @@ -0,0 +1,21 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +// Replacement simplifies the creation of a `map[string]string` with validation. +type Replacement struct { + Old string `tfsdk:"old"` + New string `tfsdk:"new"` +} diff --git a/corefuncprovider/provider.go b/corefuncprovider/provider.go index e5cfbc15..2b6994b1 100644 --- a/corefuncprovider/provider.go +++ b/corefuncprovider/provider.go @@ -104,6 +104,7 @@ func (p *coreFuncProvider) DataSources(ctx context.Context) []func() datasource. EnvEnsureDataSource, StrCamelDataSource, StrConstantDataSource, + StrIterativeReplaceDataSource, StrKebabDataSource, StrPascalDataSource, StrSnakeDataSource, diff --git a/corefuncprovider/str_iterative_replace_data_source.go b/corefuncprovider/str_iterative_replace_data_source.go new file mode 100644 index 00000000..8c4b900f --- /dev/null +++ b/corefuncprovider/str_iterative_replace_data_source.go @@ -0,0 +1,186 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package corefuncprovider // lint:no_dupe + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/lithammer/dedent" + "github.com/northwood-labs/terraform-provider-corefunc/corefunc" + cfTypes "github.com/northwood-labs/terraform-provider-corefunc/corefunc/types" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &strIterativeReplaceDataSource{} + _ datasource.DataSourceWithConfigure = &strIterativeReplaceDataSource{} +) + +type ( + // strIterativeReplaceDataSource is the data source implementation. + strIterativeReplaceDataSource struct{} + + // strIterativeReplaceDataSourceModel maps the data source schema data. + strIterativeReplaceDataSourceModel struct { + ID types.Int64 `tfsdk:"id"` + String types.String `tfsdk:"string"` + Value types.String `tfsdk:"value"` + Replacements []cfTypes.Replacement `tfsdk:"replacements"` + } +) + +// StrIterativeReplaceDataSource is a method that exposes its paired Go function as a +// Terraform Data Source. +func StrIterativeReplaceDataSource() datasource.DataSource { // lint:allow_return_interface + return &strIterativeReplaceDataSource{} +} + +// Metadata returns the data source type name. +func (d *strIterativeReplaceDataSource) Metadata( + ctx context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { + tflog.Info(ctx, "Starting StrIterativeReplace DataSource Metadata method.") + + resp.TypeName = req.ProviderTypeName + "_str_iterative_replace" + + tflog.Debug(ctx, fmt.Sprintf("req.ProviderTypeName = %s", req.ProviderTypeName)) + tflog.Debug(ctx, fmt.Sprintf("resp.TypeName = %s", resp.TypeName)) + + tflog.Info(ctx, "Ending StrIterativeReplace DataSource Metadata method.") +} + +// Schema defines the schema for the data source. +func (d *strIterativeReplaceDataSource) Schema( + ctx context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { + tflog.Info(ctx, "Starting StrIterativeReplace DataSource Schema method.") + + resp.Schema = schema.Schema{ + MarkdownDescription: strings.TrimSpace(dedent.Dedent(` + Performs a series of replacements against a string. Allows a Terraform + module to accept a set of replacements from a user. + + Maps to the [` + "`" + `corefunc.StrIterativeReplace()` + "`" + `](URL) + Go method, which can be used in ` + Terratest + `. + `)), + Attributes: map[string]schema.Attribute{ + "id": schema.Int64Attribute{ + Description: "Not used. Required by the " + TPF + ".", + Computed: true, + }, + "string": schema.StringAttribute{ + Description: "The string upon which replacements should be applied.", + Required: true, + }, + "replacements": schema.ListAttribute{ + Description: strings.TrimSpace(dedent.Dedent(` + A list of maps. Each map has an ` + "`" + `old` + "`" + ` and ` + "`" + `new` + "`" + + ` key. ` + "`" + `old` + "`" + ` represents the existing string to be replaced, and ` + "`" + + `new` + "`" + ` represents the replacement string. + `)), + Required: true, + ElementType: types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "old": types.StringType, + "new": types.StringType, + }, + }, + }, + "value": schema.StringAttribute{ + Description: "The value of the string.", + Computed: true, + }, + }, + } + + tflog.Info(ctx, "Ending StrIterativeReplace DataSource Schema method.") +} + +// Configure adds the provider configured client to the data source. +func (d *strIterativeReplaceDataSource) Configure( + ctx context.Context, + req datasource.ConfigureRequest, + _ *datasource.ConfigureResponse, +) { + tflog.Info(ctx, "Starting StrIterativeReplace DataSource Configure method.") + + if req.ProviderData == nil { + return + } + + tflog.Info(ctx, "Ending StrIterativeReplace DataSource Configure method.") +} + +func (d strIterativeReplaceDataSource) Create( + ctx context.Context, + req resource.CreateRequest, // lint:allow_large_memory + resp *resource.CreateResponse, +) { + tflog.Info(ctx, "Starting StrIterativeReplace DataSource Create method.") + + var plan strIterativeReplaceDataSourceModel + + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Info(ctx, "Ending StrIterativeReplace DataSource Create method.") +} + +// Read refreshes the Terraform state with the latest data. +func (d *strIterativeReplaceDataSource) Read( // lint:no_dupe + ctx context.Context, + _ datasource.ReadRequest, // lint:allow_large_memory + resp *datasource.ReadResponse, +) { + tflog.Info(ctx, "Starting StrIterativeReplace DataSource Read method.") + + var state strIterativeReplaceDataSourceModel + diags := resp.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + + state.ID = types.Int64Value(1) + + state.Value = types.StringValue( + corefunc.StrIterativeReplace( + state.String.ValueString(), + state.Replacements, + ), + ) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Info(ctx, "Ending StrIterativeReplace DataSource Read method.") +} diff --git a/corefuncprovider/str_iterative_replace_data_source_fixture.tftpl b/corefuncprovider/str_iterative_replace_data_source_fixture.tftpl new file mode 100644 index 00000000..75ae191b --- /dev/null +++ b/corefuncprovider/str_iterative_replace_data_source_fixture.tftpl @@ -0,0 +1,12 @@ +data "corefunc_str_iterative_replace" "replacements" { + string = "{{ .Input }}" + replacements = [ +{{- with .Replacements }}{{- range . }} + { + old = "{{- .Old -}}" + new = "{{- .New -}}" + }, +{{- end }}{{- end }} + ] +} +#=> {{ .Expected }} diff --git a/corefuncprovider/str_iterative_replace_data_source_test.go b/corefuncprovider/str_iterative_replace_data_source_test.go new file mode 100644 index 00000000..30574616 --- /dev/null +++ b/corefuncprovider/str_iterative_replace_data_source_test.go @@ -0,0 +1,67 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package corefuncprovider + +import ( + "bytes" + "fmt" + "log" + "os" + "strings" + "testing" + "text/template" + + "github.com/northwood-labs/terraform-provider-corefunc/testfixtures" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccStrIterativeReplaceDataSource(t *testing.T) { + funcName := traceFuncName() + + for name, tc := range testfixtures.StrIterativeReplaceTestTable { + fmt.Printf( + "=== RUN %s/%s\n", + strings.TrimSpace(funcName), + strings.TrimSpace(name), + ) + + buf := new(bytes.Buffer) + tmpl := template.Must( + template.ParseFiles("str_iterative_replace_data_source_fixture.tftpl"), + ) + + err := tmpl.Execute(buf, tc) + if err != nil { + log.Fatalln(err) + } + + if os.Getenv("PROVIDER_DEBUG") != "" { + fmt.Fprintln(os.Stderr, buf.String()) + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: providerConfig + buf.String(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.corefunc_str_iterative_replace.replacements", "value", tc.Expected), + ), + }, + }, + }) + } +} diff --git a/docs/data-sources/str_iterative_replace.md b/docs/data-sources/str_iterative_replace.md new file mode 100644 index 00000000..772b167e --- /dev/null +++ b/docs/data-sources/str_iterative_replace.md @@ -0,0 +1,78 @@ + + +# corefunc_str_iterative_replace (Data Source) + +Performs a series of replacements against a string. Allows a Terraform +module to accept a set of replacements from a user. + +Maps to the [`corefunc.StrIterativeReplace()`](URL) +Go method, which can be used in [Terratest](https://terratest.gruntwork.io). + +## Example Usage + +```terraform +data "corefunc_str_iterative_replace" "replacements" { + string = "This is a string for testing replacements. New Relic. Set-up." + replacements = [ + { + old = "." + new = "" + }, + { + old = " " + new = "_" + }, + { + old = "-" + new = "_" + }, + { + old = "New_Relic" + new = "datadog" + }, + { + old = "This" + new = "this" + }, + { + old = "Set_up" + new = "setup" + }, + ] +} +#=> this_is_a_string_for_testing_replacements_datadog_setup +``` + + +## Schema + +### Required + +* `replacements` (List of Object) A list of maps. Each map has an `old` and `new` key. `old` represents the existing string to be replaced, and `new` represents the replacement string. (see [below for nested schema](#nestedatt--replacements)) +* `string` (String) The string upon which replacements should be applied. + +### Read-Only + +* `id` (Number) Not used. Required by the [Terraform Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework). +* `value` (String) The value of the string. + + + +### Nested Schema for `replacements` + +Required: + +* `new` (String) +* `old` (String) + + diff --git a/examples/data-sources/corefunc_str_iterative_replace/data-source.tf b/examples/data-sources/corefunc_str_iterative_replace/data-source.tf new file mode 100644 index 00000000..3256511d --- /dev/null +++ b/examples/data-sources/corefunc_str_iterative_replace/data-source.tf @@ -0,0 +1,30 @@ +data "corefunc_str_iterative_replace" "replacements" { + string = "This is a string for testing replacements. New Relic. Set-up." + replacements = [ + { + old = "." + new = "" + }, + { + old = " " + new = "_" + }, + { + old = "-" + new = "_" + }, + { + old = "New_Relic" + new = "datadog" + }, + { + old = "This" + new = "this" + }, + { + old = "Set_up" + new = "setup" + }, + ] +} +#=> this_is_a_string_for_testing_replacements_datadog_setup diff --git a/examples/data-sources/corefunc_str_iterative_replace/versions.tftpl b/examples/data-sources/corefunc_str_iterative_replace/versions.tftpl new file mode 100644 index 00000000..90ced86e --- /dev/null +++ b/examples/data-sources/corefunc_str_iterative_replace/versions.tftpl @@ -0,0 +1,13 @@ +terraform { + required_version = "~> 1.1, < 1.6" + + required_providers { + corefunc = { + source = "northwood-labs/corefunc" + version = "~> 1.0" + } + } +} + +# There are no configuration options +provider "corefunc" {} diff --git a/testfixtures/str_iterative_replace.go b/testfixtures/str_iterative_replace.go new file mode 100644 index 00000000..a8a0d4bc --- /dev/null +++ b/testfixtures/str_iterative_replace.go @@ -0,0 +1,39 @@ +// Copyright 2023, Ryan Parman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package testfixtures // lint:no_dupe + +import "github.com/northwood-labs/terraform-provider-corefunc/corefunc/types" + +// StrIterativeReplaceTestTable is used by both the standard Go tests and also +// the Terraform acceptance tests. +// +var StrIterativeReplaceTestTable = map[string]struct { // lint:no_dupe + Replacements []types.Replacement + Input string + Expected string +}{ + "replacements": { + Input: "This is a string for testing replacements. New Relic. Set-up.", + Replacements: []types.Replacement{ + {Old: ".", New: ""}, + {Old: " ", New: "_"}, + {Old: "-", New: "_"}, + {Old: "New_Relic", New: "datadog"}, + {Old: "This", New: "this"}, + {Old: "Set_up", New: "setup"}, + }, + Expected: "this_is_a_string_for_testing_replacements_datadog_setup", + }, +}