github.com/hattya/nazuna@v0.7.1-0.20240331055452-55e14c275c1c/cmd/nzn/clone_test.go (about) 1 // 2 // nazuna/cmd/nzn :: clone_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 TestClone(t *testing.T) { 18 s := script{ 19 { 20 cmd: []string{"setup"}, 21 }, 22 { 23 cmd: []string{"git", "init", "-q", "$public/repo"}, 24 }, 25 { 26 cmd: []string{"cd", "$public/repo"}, 27 }, 28 { 29 cmd: []string{"touch", "nazuna.json"}, 30 }, 31 { 32 cmd: []string{"git", "add", "."}, 33 }, 34 { 35 cmd: []string{"git", "commit", "-qm", "."}, 36 }, 37 { 38 cmd: []string{"cd", "$tempdir"}, 39 }, 40 { 41 cmd: []string{"nzn", "clone", "--vcs", "git", "$public/repo", "wc"}, 42 out: cli.Dedent(` 43 Cloning into '` + path("wc/.nzn/r") + `'... 44 done. 45 `), 46 }, 47 { 48 cmd: []string{"ls", "wc/.nzn"}, 49 out: cli.Dedent(` 50 r/ 51 `), 52 }, 53 { 54 cmd: []string{"ls", "wc/.nzn/r"}, 55 out: cli.Dedent(` 56 .git/ 57 nazuna.json 58 `), 59 }, 60 } 61 if err := s.exec(t); err != nil { 62 t.Error(err) 63 } 64 } 65 66 func TestCloneError(t *testing.T) { 67 s := script{ 68 { 69 cmd: []string{"setup"}, 70 }, 71 { 72 cmd: []string{"nzn", "clone"}, 73 out: cli.Dedent(` 74 nzn: invalid arguments 75 [1] 76 `), 77 }, 78 { 79 cmd: []string{"git", "init", "-q", "$public/repo"}, 80 }, 81 { 82 cmd: []string{"nzn", "clone", "$public/repo", "wc"}, 83 out: cli.Dedent(` 84 nzn clone: --vcs flag is required (re) 85 usage: nzn clone --vcs <type> <repository> [<path>] 86 87 create a copy of an existing repository 88 89 Create a copy of an existing repository in <path>. If <path> does not exist, 90 it will be created. 91 92 If <path> is not specified, the current working directory is used. 93 94 options: 95 96 --vcs <type> vcs type 97 98 [2] 99 `), 100 }, 101 { 102 cmd: []string{"nzn", "clone", "--vcs", "cvs", "$public/repo", "wc"}, 103 out: cli.Dedent(` 104 nzn: unknown vcs 'cvs' 105 [1] 106 `), 107 }, 108 { 109 cmd: []string{"nzn", "init", "--vcs", "git", "wc"}, 110 }, 111 { 112 cmd: []string{"nzn", "clone", "--vcs", "git", "$public/repo", "wc"}, 113 out: cli.Dedent(` 114 nzn: repository 'wc' already exists! 115 [1] 116 `), 117 }, 118 { 119 cmd: []string{"cd", "$wc"}, 120 }, 121 { 122 cmd: []string{"nzn", "clone", "--vcs", "git", "$public/repo"}, 123 out: cli.Dedent(` 124 nzn: repository '.' already exists! 125 [1] 126 `), 127 }, 128 } 129 if err := s.exec(t); err != nil { 130 t.Error(err) 131 } 132 }