mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
96683c8aff
set limit to 5<=x<=32
65 lines
1,015 B
Go
65 lines
1,015 B
Go
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,
|
|
},
|
|
{
|
|
Name: "longname",
|
|
Args: args{
|
|
Name: "TestvalidNameTestvalidName",
|
|
},
|
|
Want: true,
|
|
},
|
|
{
|
|
Name: "max length",
|
|
Args: args{
|
|
Name: "123456789012345",
|
|
},
|
|
Want: true,
|
|
},
|
|
{
|
|
Name: "min length",
|
|
Args: args{
|
|
Name: "ama",
|
|
},
|
|
Want: false,
|
|
},
|
|
{
|
|
Name: "toolong",
|
|
Args: args{
|
|
Name: "123456789012345123123123123123123123123123123",
|
|
},
|
|
Want: false,
|
|
},
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|