mirror of https://github.com/fluxcd/flux2.git
validate that object name adheres to RFC 1123 for flux create commands
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>pull/2443/head
parent
8c2983c958
commit
4a893b13f8
@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
)
|
||||
|
||||
func Test_validateObjectName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
valid bool
|
||||
}{
|
||||
{
|
||||
name: "flux-system",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "-flux-system",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "-flux-system-",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "third.first",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "THirdfirst",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "THirdfirst",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: rand.String(63),
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: rand.String(64),
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
valid := validateObjectName(tt.name)
|
||||
if valid != tt.valid {
|
||||
t.Errorf("expected name %q to return %t for validateObjectName func but got %t",
|
||||
tt.name, tt.valid, valid)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue