github.com/hattya/nazuna@v0.7.1-0.20240331055452-55e14c275c1c/cmd/nzn/init_test.go (about) 1 // 2 // nazuna/cmd/nzn :: init_test.go 3 // 4 // Copyright (c) 2013-2024 Akinori Hattori <hattya@gmail.com> 5 // 6 // SPDX-License-Identifier: MIT 7 // 8 9 package main 10 11 import ( 12 "testing" 13 14 "github.com/hattya/go.cli" 15 ) 16 17 func TestInit(t *testing.T) { 18 s := script{ 19 { 20 cmd: []string{"setup"}, 21 }, 22 { 23 cmd: []string{"nzn", "init", "--vcs", "git", "$wc"}, 24 }, 25 { 26 cmd: []string{"ls", "$wc/.nzn"}, 27 out: cli.Dedent(` 28 r/ 29 `), 30 }, 31 { 32 cmd: []string{"ls", "$wc/.nzn/r"}, 33 out: cli.Dedent(` 34 .git/ 35 nazuna.json 36 `), 37 }, 38 { 39 cmd: []string{"cat", "$wc/.nzn/r/nazuna.json"}, 40 out: cli.Dedent(` 41 [] 42 `), 43 }, 44 } 45 if err := s.exec(t); err != nil { 46 t.Error(err) 47 } 48 } 49 50 func TestInitError(t *testing.T) { 51 s := script{ 52 { 53 cmd: []string{"setup"}, 54 }, 55 { 56 cmd: []string{"nzn", "init", "$wc"}, 57 out: cli.Dedent(` 58 nzn init: --vcs flag is required 59 usage: nzn init --vcs <type> [<path>] 60 61 create a new repository in the specified directory 62 63 Create a new repository in <path>. If <path> does not exist, it will be 64 created. 65 66 If <path> is not specified, the current working directory is used. 67 68 options: 69 70 --vcs <type> vcs type 71 72 [2] 73 `), 74 }, 75 { 76 cmd: []string{"nzn", "init", "--vcs", "cvs", "$wc"}, 77 out: cli.Dedent(` 78 nzn: unknown vcs 'cvs' 79 [1] 80 `), 81 }, 82 { 83 cmd: []string{"mkdir", "$wc/.nzn/r"}, 84 }, 85 { 86 cmd: []string{"nzn", "init", "--vcs", "git", "$wc"}, 87 out: cli.Dedent(` 88 nzn: repository '.+' already exists! (re) 89 [1] 90 `), 91 }, 92 } 93 if err := s.exec(t); err != nil { 94 t.Error(err) 95 } 96 }