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

Function TestCreateCmd

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

Source from the content-addressed store, hash-verified

237}
238
239func TestCreateCmd(t *testing.T) {
240 celer := newInitializedCeler(t)
241
242 // ============= Create platform ============= //
243 t.Run("CreatePlatformSuccess", func(t *testing.T) {
244 const platformName = "x86_64-linux-ubuntu-test"
245 cmd := &createCmd{}
246 if _, err := runCommand(t, cmd.Command(celer), "--platform="+platformName); err != nil {
247 t.Fatal(err)
248 }
249
250 // Check if platform really created.
251 platformPath := filepath.Join(dirs.ConfPlatformsDir, platformName+".toml")
252 if !fileio.PathExists(platformPath) {
253 t.Errorf("platform file does not exist: %s", platformPath)
254 }
255
256 t.Cleanup(func() {
257 _ = os.RemoveAll(platformPath)
258 })
259 })
260
261 t.Run("CreatePlatformFailed_emptyName", func(t *testing.T) {
262 cmd := &createCmd{}
263 stderr, err := runCommand(t, cmd.Command(celer), "--platform=")
264 if err == nil {
265 t.Fatal("expected error when --platform is empty")
266 }
267 if !strings.Contains(stderr, "cannot be empty") {
268 t.Fatalf("stderr should report empty name, got:\n%s", stderr)
269 }
270 })
271
272 // ============= Create project ============= //
273 t.Run("CreateProjectSuccess", func(t *testing.T) {
274 const projectName = "project_test_create"
275 cmd := &createCmd{}
276 if _, err := runCommand(t, cmd.Command(celer), "--project="+projectName); err != nil {
277 t.Fatal(err)
278 }
279
280 projectPath := filepath.Join(dirs.ConfProjectsDir, projectName+".toml")
281 if !fileio.PathExists(projectPath) {
282 t.Errorf("project does not exist: %s", projectName)
283 }
284
285 t.Cleanup(func() {
286 _ = os.Remove(projectPath)
287 })
288 })
289
290 t.Run("CreateProjectFailed_emptyName", func(t *testing.T) {
291 cmd := &createCmd{}
292 stderr, err := runCommand(t, cmd.Command(celer), "--project=")
293 if err == nil {
294 t.Fatal("expected error when --project is empty")
295 }
296 if !strings.Contains(stderr, "cannot be empty") {

Callers

nothing calls this directly

Calls 6

CommandMethod · 0.95
PathExistsFunction · 0.92
GetPortPathFunction · 0.92
newInitializedCelerFunction · 0.85
runCommandFunction · 0.85
RemoveMethod · 0.45

Tested by

no test coverage detected