* 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
63 lines
1.4 KiB
Go
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())
|
|
})
|
|
}
|
|
}
|