2023-05-17 22:58:03 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
// TestValidName tests the validName function
|
|
|
|
func TestValidName(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
Name string
|
|
|
|
Args args
|
|
|
|
Want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "validName",
|
|
|
|
Args: args{
|
|
|
|
Name: "TestvalidName",
|
|
|
|
},
|
|
|
|
Want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "invalidName",
|
|
|
|
Args: args{
|
|
|
|
Name: "Test*Name",
|
|
|
|
},
|
|
|
|
Want: false,
|
|
|
|
},
|
|
|
|
{
|
2023-08-08 18:29:02 +08:00
|
|
|
Name: "longname",
|
2023-05-17 22:58:03 +08:00
|
|
|
Args: args{
|
|
|
|
Name: "TestvalidNameTestvalidName",
|
|
|
|
},
|
2023-08-08 18:29:02 +08:00
|
|
|
Want: true,
|
2023-05-17 22:58:03 +08:00
|
|
|
},
|
|
|
|
{
|
2023-08-08 18:29:02 +08:00
|
|
|
Name: "max length",
|
2023-05-17 22:58:03 +08:00
|
|
|
Args: args{
|
|
|
|
Name: "123456789012345",
|
|
|
|
},
|
|
|
|
Want: true,
|
|
|
|
},
|
2023-08-08 18:29:02 +08:00
|
|
|
{
|
|
|
|
Name: "min length",
|
|
|
|
Args: args{
|
|
|
|
Name: "ama",
|
|
|
|
},
|
|
|
|
Want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "toolong",
|
|
|
|
Args: args{
|
|
|
|
Name: "123456789012345123123123123123123123123123123",
|
|
|
|
},
|
|
|
|
Want: false,
|
|
|
|
},
|
2023-05-17 22:58:03 +08:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.Name, func(t *testing.T) {
|
|
|
|
if got := validName(tt.Args.Name); got != tt.Want {
|
|
|
|
t.Errorf("validName() = %v, want %v", got, tt.Want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|