Files
terraform-provider-unifi/internal/provider/validators/string_length_exactly_test.go
Mateusz Filipowicz a36940b019 feat: add country setting resource support with unifi_setting_country resource (#31)
* feat: add country setting resource support with `unifi_setting_country` resource

* linting
2025-02-27 02:56:07 +01:00

36 lines
752 B
Go

package validators
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestStringLengthExactlyValidation(t *testing.T) {
t.Parallel()
testCases := []struct {
value string
length int
validationFailed bool
}{
{"", 0, false},
{"", 1, true},
{"a", 0, true},
{"a", 1, false},
{"a", 2, true},
{"ab", 2, false},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s-expected-length-%d", tc.value, tc.length), func(t *testing.T) {
t.Parallel()
v := StringLengthExactly(tc.length)
req, resp := newStringValidatorRequestResponse(tc.value)
v.ValidateString(context.Background(), req, resp)
assert.Equal(t, tc.validationFailed, resp.Diagnostics.HasError())
})
}
}