github.com/weaviate/weaviate@v1.24.6/entities/schema/validation_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package schema 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestValidateOKClassName(t *testing.T) { 21 for _, name := range []string{ 22 "A", 23 "FooBar", 24 "FooBar2", 25 "Foo_______bar__with_numbers___1234567890_and_2", 26 "C_123456___foo_bar_2", 27 "NormalClassNameWithNumber1", 28 "Normal__Class__Name__With__Number__1", 29 "CClassName", 30 "ThisClassNameHasExactly255Characters_MaximumAllowed____________________qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890", 31 } { 32 t.Run(name, func(t *testing.T) { 33 _, err := ValidateClassName(name) 34 assert.NoError(t, err) 35 }) 36 } 37 } 38 39 func TestFailValidateBadClassName(t *testing.T) { 40 for _, name := range []string{ 41 "", 42 "Foo Bar", 43 "foo", 44 "fooBar", 45 "_foo", 46 "ThisClassNameHasMoreThan255Characters_MaximumAllowed____________________qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890", 47 } { 48 t.Run(name, func(t *testing.T) { 49 _, err := ValidateClassName(name) 50 assert.Error(t, err) 51 }) 52 } 53 } 54 55 func TestValidateOKPropertyName(t *testing.T) { 56 for _, name := range []string{ 57 "fooBar", 58 "fooBar2", 59 "_fooBar2", 60 "intField", 61 "hasAction", 62 "_foo_bar_2", 63 "______foo_bar_2", 64 "___123456___foo_bar_2", 65 "a_very_Long_property_Name__22_with_numbers_9", 66 "a_very_Long_property_Name__22_with_numbers_9880888800888800008", 67 "FooBar", 68 "ThisPropertyNameHasExactly231Characters_MaximumAllowed______________________________qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890", 69 } { 70 t.Run(name, func(t *testing.T) { 71 _, err := ValidatePropertyName(name) 72 assert.NoError(t, err) 73 }) 74 } 75 } 76 77 func TestFailValidateBadPropertyName(t *testing.T) { 78 for _, name := range []string{ 79 "foo Bar", 80 "a_very_Long_property_Name__22_with-dash_9", 81 "1_FooBar", 82 "ThisPropertyNameHasMoreThan231Characters_MaximumAllowed______________________________qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890_qwertyuiopasdfghjklzxcvbnm1234567890", 83 } { 84 t.Run(name, func(t *testing.T) { 85 _, err := ValidatePropertyName(name) 86 assert.Error(t, err) 87 }) 88 } 89 } 90 91 func TestValidateReservedPropertyName(t *testing.T) { 92 type args struct { 93 name string 94 } 95 tests := []struct { 96 name string 97 args args 98 wantErr bool 99 }{ 100 { 101 name: "Reserved name: _additional", 102 args: args{ 103 name: "_additional", 104 }, 105 wantErr: true, 106 }, 107 { 108 name: "Reserved name: id", 109 args: args{ 110 name: "id", 111 }, 112 wantErr: true, 113 }, 114 { 115 name: "Reserved name: _id", 116 args: args{ 117 name: "_id", 118 }, 119 wantErr: true, 120 }, 121 } 122 for _, tt := range tests { 123 t.Run(tt.name, func(t *testing.T) { 124 if err := ValidateReservedPropertyName(tt.args.name); (err != nil) != tt.wantErr { 125 t.Errorf("ValidateReservedPropertyName() error = %v, wantErr %v", err, tt.wantErr) 126 } 127 }) 128 } 129 }