package model import ( "testing" ) func TestStrings_UnmarshalJSON(t *testing.T) { tests := []struct { name string input string want interface{} wantErr bool }{ { name: "valid string", input: `"test"`, want: "test", }, { name: "valid array", input: `["a","b"]`, want: []string{"a", "b"}, }, { name: "invalid type", input: `123`, wantErr: true, }, { name: "invalid array type", input: `["a", 123]`, wantErr: true, }, } for _, tt := range tests { s := &Strings{} err := s.UnmarshalJSON([]byte(tt.input)) if tt.wantErr { if err == nil { t.Errorf("%s: expected error but got none", tt.name) } continue } if err != nil { t.Errorf("%s: unexpected error %v", tt.name, err) continue } } } func TestStrings_HasOrContainPrefix(t *testing.T) { tests := []struct { name string input string value string want bool wantErr bool }{ { name: "valid string", input: `"test"`, value: "test", want: true, }, { name: "valid array", input: `["a","b"]`, value: "a", want: true, }, } for _, tt := range tests { s := &Strings{} err := s.UnmarshalJSON([]byte(tt.input)) if err != nil { t.Errorf("%s: unexpected error %v", tt.name, err) continue } got := s.HasOrContainPrefix(tt.value) if got != tt.want { t.Errorf("%s: expected %v, got %v", tt.name, tt.want, got) } } }