MCPcopy Create free account
hub / github.com/celer-pkg/celer / TestCreateCmd_Validation

Function TestCreateCmd_Validation

cmds/cmd_create_test.go:122–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestCreateCmd_Validation(t *testing.T) {
123 // Cleanup.
124 dirs.RemoveAllForTest()
125
126 createCmd := &createCmd{}
127
128 t.Run("validatePlatformName", func(t *testing.T) {
129 tests := []struct {
130 name string
131 input string
132 expectError bool
133 }{
134 {"valid platform name", "windows-x86_64-msvc", false},
135 {"empty platform name", "", true},
136 {"whitespace only", " ", true},
137 {"platform with spaces", "windows x86_64", true},
138 {"valid complex name", "x86_64-linux-gnu-gcc", false},
139 {"platform path traversal", "../windows-x86_64-msvc", true},
140 {"platform with slash", "windows/x86_64", true},
141 }
142
143 for _, test := range tests {
144 t.Run(test.name, func(t *testing.T) {
145 err := createCmd.validatePlatformName(test.input)
146 if test.expectError && err == nil {
147 t.Errorf("Expected error for input '%s' but got none", test.input)
148 } else if !test.expectError && err != nil {
149 t.Errorf("Expected no error for input '%s' but got: %v", test.input, err)
150 }
151 })
152 }
153 })
154
155 t.Run("validateProjectName", func(t *testing.T) {
156 tests := []struct {
157 name string
158 input string
159 expectError bool
160 }{
161 {"valid project name", "my-awesome-project", false},
162 {"empty project name", "", true},
163 {"whitespace only", " ", true},
164 {"project with spaces", "my project", false}, // Project names can have spaces
165 {"valid with numbers", "project123", false},
166 {"project path traversal", "../my-project", true},
167 {"project with slash", "my/project", true},
168 }
169
170 for _, test := range tests {
171 t.Run(test.name, func(t *testing.T) {
172 err := createCmd.validateProjectName(test.input)
173 if test.expectError && err == nil {
174 t.Errorf("Expected error for input '%s' but got none", test.input)
175 } else if !test.expectError && err != nil {
176 t.Errorf("Expected no error for input '%s' but got: %v", test.input, err)
177 }
178 })
179 }

Callers

nothing calls this directly

Calls 4

validatePlatformNameMethod · 0.95
validateProjectNameMethod · 0.95
validatePortNameMethod · 0.95
RemoveAllForTestFunction · 0.92

Tested by

no test coverage detected