Files
terraform-provider-unifi/internal/provider/settings/resource_setting_country_test.go
Mateusz Filipowicz fcea1e0ba4 feat: support complete USG resource (#44)
* feat: add support for UPNP and Geo IP filtering to USG settings resource

* feat: support complete USG settings resource

* fix messages in required_together_if.go

* improve docs of USG resource

* tests: require version at least 9.0 for unbind_wan_monitors

* feat: require version at least 8.5 for dns_verification

* fix: use go-unifi 1.5.2 to fix NTP

* require 7.0 or later for timeout preference

* require 7.0 or later for geo IP filtering
2025-03-11 02:17:24 +01:00

63 lines
1.4 KiB
Go

package settings
import (
"context"
"github.com/filipowm/go-unifi/unifi"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSettingCountry_ProperCountryCodeMappingFromModel(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
code string
expectedNumericCode int
}{
{"Poland", "PL", 616},
{"United States", "US", 840},
{"Unknown", "WP", 0},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
model := countryModel{
Code: types.StringValue(tc.code),
}
unifiModel, _ := model.AsUnifiModel(context.Background())
typed, ok := unifiModel.(*unifi.SettingCountry)
assert.True(t, ok)
assert.Equal(t, tc.expectedNumericCode, typed.Code)
})
}
}
func TestSettingCountry_ProperCountryCodeMappingToModel(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
numericCode int
expectedCode string
}{
{"Poland", 616, "PL"},
{"United States", 840, "US"},
{"Unknown", 0, "Unknown"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
unifiModel := &unifi.SettingCountry{
Code: tc.numericCode,
}
model := countryModel{}
model.Merge(context.Background(), unifiModel)
assert.Equal(t, tc.expectedCode, model.Code.ValueString())
})
}
}