Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(no-release): [Backward compatibility] routeros_ip_firewall_filter NOT WORKING AS EXPECTED #424

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions routeros/provider_schema_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,13 @@ var (

// Properties DiffSuppressFunc.
var (
defaultTimeReplace = strings.NewReplacer("none-dynamic", "", "none", "")

TimeEquall = func(k, old, new string, d *schema.ResourceData) bool {
if old == new {
return true
}
old = defaultTimeReplace.Replace(old)
new = defaultTimeReplace.Replace(new)

if (old == "none" && new == "") || (old == "" && new == "none") {
if old == new {
return true
}

Expand Down
37 changes: 37 additions & 0 deletions routeros/provider_schema_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func TestValidationMultiValInSlice(t *testing.T) {
Expand Down Expand Up @@ -158,3 +159,39 @@ func Test_toQuotedCommaSeparatedString(t *testing.T) {
})
}
}

func TestTimeEquall(t *testing.T) {
type args struct {
old string
new string
d *schema.ResourceData
}
tests := []struct {
name string
args args
want bool
}{
{"TimeEquall #1", args{"", "", nil}, true},
{"TimeEquall #2", args{"none", "none", nil}, true},
{"TimeEquall #3", args{"none-dynamic", "none-dynamic", nil}, true},
{"TimeEquall #4", args{"none", "", nil}, true},
{"TimeEquall #5", args{"", "none", nil}, true},
{"TimeEquall #6", args{"none-dynamic", "", nil}, true},
{"TimeEquall #7", args{"", "none-dynamic", nil}, true},
{"TimeEquall #8", args{"", "1m20s", nil}, false},
{"TimeEquall #9", args{"1m20s", "", nil}, false},
{"TimeEquall #10", args{"none", "1m20s", nil}, false},
{"TimeEquall #11", args{"1m20s", "none", nil}, false},
{"TimeEquall #12", args{"none-dynamic", "1m20s", nil}, false},
{"TimeEquall #13", args{"1m20s", "none-dynamic", nil}, false},
{"TimeEquall #14", args{"1m20s", "1h30m", nil}, false},
{"TimeEquall #15", args{"1m20s", "80s", nil}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := TimeEquall("", tt.args.old, tt.args.new, tt.args.d); got != tt.want {
t.Errorf("TimeEquall() = %v, want %v", got, tt.want)
}
})
}
}
9 changes: 4 additions & 5 deletions routeros/resource_ip_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func ResourceIPFirewallFilter() *schema.Resource {
"address_list_timeout": {
Type: schema.TypeString,
Optional: true,
Default: "none-dynamic",
Description: "Time interval after which the address will be removed from the address list specified by " +
"address-list parameter. Used in conjunction with add-dst-to-address-list or add-src-to-address-list " +
"actions.",
Expand Down Expand Up @@ -226,10 +225,10 @@ func ResourceIPFirewallFilter() *schema.Resource {
"rate[/time],burst:mode.",
},
"log": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Add a message to the system log.",
Type: schema.TypeBool,
Optional: true,
Description: "Add a message to the system log.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"log_prefix": {
Type: schema.TypeString,
Expand Down
Loading