github.com/azunymous/cdx@v0.0.0-20201122180449-fbb46cc4d252/test/e2e/tag/release_test.go (about) 1 //+build e2e 2 3 package tag 4 5 import ( 6 "github.com/azunymous/cdx/test/check" 7 "github.com/azunymous/cdx/test/e2e" 8 "os" 9 "os/exec" 10 "strings" 11 "testing" 12 ) 13 14 func TestReleaseOpensRepository(t *testing.T) { 15 e2e.CreateTempGitDir() 16 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app") 17 err := command.Run() 18 check.Ok(t, err) 19 } 20 21 func TestReleaseTagsRepository(t *testing.T) { 22 dir := e2e.CreateTempGitDir() 23 e2e.CreateTag(dir, "app-0.1.0") 24 e2e.CreateCommit(dir, "Commit 2") 25 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app") 26 err := command.Run() 27 check.Ok(t, err) 28 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 29 check.Ok(t, err) 30 check.Equals(t, "app-0.2.0", strings.TrimSpace(string(output))) 31 } 32 33 func TestReleaseTagsRepositoryAlreadyReleased(t *testing.T) { 34 dir := e2e.CreateTempGitDir() 35 e2e.CreateTag(dir, "app-0.1.0") 36 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app") 37 err := command.Run() 38 check.Ok(t, err) 39 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 40 check.Ok(t, err) 41 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 42 } 43 44 func TestReleaseTagsRepositoryFirstRelease(t *testing.T) { 45 e2e.CreateTempGitDir() 46 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app") 47 err := command.Run() 48 check.Ok(t, err) 49 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 50 check.Ok(t, err) 51 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 52 } 53 54 func TestReleaseTagsRepository_patch(t *testing.T) { 55 e2e.CreateTempGitDir() 56 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "-i", "patch") 57 err := command.Run() 58 check.Ok(t, err) 59 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 60 check.Ok(t, err) 61 check.Equals(t, "app-0.0.1", strings.TrimSpace(string(output))) 62 } 63 64 func TestReleaseTagsRepository_minor(t *testing.T) { 65 e2e.CreateTempGitDir() 66 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "-i", "minor") 67 err := command.Run() 68 check.Ok(t, err) 69 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 70 check.Ok(t, err) 71 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 72 } 73 74 func TestReleaseTagsRepository_major(t *testing.T) { 75 e2e.CreateTempGitDir() 76 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "-i", "major") 77 err := command.Run() 78 check.Ok(t, err) 79 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 80 check.Ok(t, err) 81 check.Equals(t, "app-1.0.0", strings.TrimSpace(string(output))) 82 } 83 84 func TestReleaseTagsRepositoryAndPushesTags(t *testing.T) { 85 fn := e2e.CreateTempGitDir() 86 rd := e2e.CreateTempGitRemote(fn) 87 88 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 89 err := command.Run() 90 check.Ok(t, err) 91 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 92 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 93 check.Ok(t, err) 94 _ = os.Chdir(rd) 95 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 96 check.Ok(t, err) 97 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 98 } 99 100 func TestReleaseDoesNotTagNonOriginMasterWithPushFlag(t *testing.T) { 101 dir := e2e.CreateTempGitDir() 102 rd := e2e.CreateTempGitRemote(dir) 103 e2e.CreateTag(dir, "app-0.1.0") 104 _ = exec.Command("git", "checkout", "-b", "test-branch").Run() 105 106 e2e.CreateCommit(dir, "Commit 2") 107 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 108 err := command.Run() 109 check.Ok(t, err) 110 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 111 check.Ok(t, err) 112 check.Equals(t, "", strings.TrimSpace(string(output))) 113 114 _ = os.Chdir(rd) 115 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 116 check.Ok(t, err) 117 check.Equals(t, "", strings.TrimSpace(string(output))) 118 } 119 120 func TestReleaseTagsDoesNotFailIfAlreadyTaggedLocallyWithPushFlag(t *testing.T) { 121 dir := e2e.CreateTempGitDir() 122 rd := e2e.CreateTempGitRemote(dir) 123 e2e.CreateTag(dir, "app-0.1.0") 124 e2e.CreateCommit(dir, "Commit 2") 125 _ = exec.Command("git", "checkout", "HEAD~1", "--detach").Run() 126 127 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 128 err := command.Run() 129 check.Ok(t, err) 130 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 131 check.Ok(t, err) 132 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 133 134 _ = os.Chdir(rd) 135 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 136 check.Ok(t, err) 137 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 138 } 139 140 func TestReleaseTagsRepositoryDoesNotFailifAlreadyTaggedRemotelyWithPushFlag(t *testing.T) { 141 dir := e2e.CreateTempGitDir() 142 e2e.CreateTag(dir, "app-0.1.0") 143 rd := e2e.CreateTempGitRemote(dir) 144 _, _ = exec.Command("git", "push", "--tags").CombinedOutput() 145 _ = exec.Command("git", "checkout", "HEAD", "--detach").Run() 146 147 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 148 err := command.Run() 149 check.Ok(t, err) 150 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 151 check.Ok(t, err) 152 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 153 154 _ = os.Chdir(rd) 155 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 156 check.Ok(t, err) 157 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 158 } 159 160 func TestReleaseWithPushFlagFailsWhenNoRemote(t *testing.T) { 161 dir := e2e.CreateTempGitDir() 162 e2e.CreateTag(dir, "app-0.1.0") 163 e2e.CreateCommit(dir, "Commit 2") 164 165 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 166 err := command.Run() 167 check.Assert(t, err != nil, "expecting error to not be nil, got %v", err) 168 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 169 check.Ok(t, err) 170 check.Equals(t, "", strings.TrimSpace(string(output))) 171 } 172 173 func TestReleaseTagsRepositoryAndPushesAllTags(t *testing.T) { 174 fn := e2e.CreateTempGitDir() 175 e2e.CreateTag(fn, "app-0.1.0") 176 e2e.CreateCommit(fn, "commit 2") 177 rd := e2e.CreateTempGitRemote(fn) 178 179 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 180 err := command.Run() 181 check.Ok(t, err) 182 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 183 check.Equals(t, "app-0.2.0", strings.TrimSpace(string(output))) 184 check.Ok(t, err) 185 _ = os.Chdir(rd) 186 output, err = exec.Command("git", "tag", "--points-at", "HEAD~1").CombinedOutput() 187 check.Ok(t, err) 188 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 189 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 190 check.Ok(t, err) 191 check.Equals(t, "app-0.2.0", strings.TrimSpace(string(output))) 192 } 193 194 func TestReleaseTagsRepositoryAndPushesTags_detachedHead(t *testing.T) { 195 fn := e2e.CreateTempGitDir() 196 rd := e2e.CreateTempGitRemote(fn) 197 _ = exec.Command("git", "checkout", "master", "--detach").Run() 198 199 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 200 err := command.Run() 201 check.Ok(t, err) 202 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 203 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 204 check.Ok(t, err) 205 _ = os.Chdir(rd) 206 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 207 check.Ok(t, err) 208 check.Equals(t, "app-0.1.0", strings.TrimSpace(string(output))) 209 } 210 211 func TestReleaseTagsRepositoryAndPushesTags_detachedHeadAndNonHeadTags(t *testing.T) { 212 fn := e2e.CreateTempGitDir() 213 rd := e2e.CreateTempGitRemote(fn) 214 e2e.CreateTag(fn, "app-0.1.0") 215 e2e.CreateCommit(fn, "commit 2") 216 e2e.CreateCommit(fn, "commit 3") 217 _ = exec.Command("git", "push", "origin", "master").Run() 218 _ = exec.Command("git", "checkout", "HEAD~1", "--detach").Run() 219 220 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 221 err := command.Run() 222 check.Ok(t, err) 223 _ = exec.Command("git", "checkout", "master").Run() 224 output, err := exec.Command("git", "tag", "--points-at", "HEAD~1").CombinedOutput() 225 check.Equals(t, "app-0.2.0", strings.TrimSpace(string(output))) 226 check.Ok(t, err) 227 _ = os.Chdir(rd) 228 output, err = exec.Command("git", "tag", "--points-at", "HEAD~1").CombinedOutput() 229 check.Ok(t, err) 230 check.Equals(t, "app-0.2.0", strings.TrimSpace(string(output))) 231 } 232 233 func TestReleaseTagsRepositoryAndPushesTags_detachedHead_FailsWhenNotOnOriginMaster(t *testing.T) { 234 fn := e2e.CreateTempGitDir() 235 rd := e2e.CreateTempGitRemote(fn) 236 e2e.CreateTag(fn, "app-0.1.0") 237 e2e.CreateCommit(fn, "commit 2") 238 _ = exec.Command("git", "push", "origin", "master").Run() 239 240 e2e.CreateCommit(fn, "commit 3") 241 _ = exec.Command("git", "checkout", "HEAD", "--detach").Run() 242 243 command := exec.Command(e2e.CDX, "tag", "release", "-n", "app", "--push") 244 err := command.Run() 245 check.Ok(t, err) 246 _ = exec.Command("git", "checkout", "master").Run() 247 output, err := exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 248 check.Equals(t, "", strings.TrimSpace(string(output))) 249 check.Ok(t, err) 250 _ = os.Chdir(rd) 251 output, err = exec.Command("git", "tag", "--points-at", "HEAD").CombinedOutput() 252 check.Ok(t, err) 253 check.Equals(t, "", strings.TrimSpace(string(output))) 254 }