github.com/drone/runner-go@v1.12.0/clone/clone_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package clone 6 7 import ( 8 "testing" 9 10 "github.com/google/go-cmp/cmp" 11 ) 12 13 func TestCommandsTag(t *testing.T) { 14 args := Args{ 15 Depth: 50, 16 Remote: "https://github.com/octocat/hello-world.git", 17 Ref: "refs/tags/v1.0.0", 18 } 19 got := Commands(args) 20 want := []string{ 21 "git init", 22 "git remote add origin https://github.com/octocat/hello-world.git", 23 "git fetch --depth=50 origin +refs/tags/v1.0.0:", 24 "git checkout -qf FETCH_HEAD", 25 } 26 if diff := cmp.Diff(got, want); diff != "" { 27 t.Fail() 28 t.Log(diff) 29 } 30 } 31 32 func TestCommandsBranch(t *testing.T) { 33 args := Args{ 34 Branch: "develop", 35 Commit: "3650a5d21bbf086fa8d2f16b0067ddeecfa604df", 36 Depth: 50, 37 NoFF: true, 38 Remote: "https://github.com/octocat/hello-world.git", 39 Ref: "refs/heads/develop", 40 Tags: true, 41 } 42 got := Commands(args) 43 want := []string{ 44 "git init", 45 "git remote add origin https://github.com/octocat/hello-world.git", 46 "git fetch --depth=50 --tags origin +refs/heads/develop:", 47 "git checkout 3650a5d21bbf086fa8d2f16b0067ddeecfa604df -b develop", 48 } 49 if diff := cmp.Diff(got, want); diff != "" { 50 t.Log(want) 51 t.Fail() 52 t.Log(diff) 53 } 54 } 55 56 func TestCommandsPullRequest(t *testing.T) { 57 args := Args{ 58 Branch: "master", 59 Commit: "3650a5d21bbf086fa8d2f16b0067ddeecfa604df", 60 Depth: 50, 61 NoFF: true, 62 Remote: "https://github.com/octocat/hello-world.git", 63 Ref: "refs/pull/42/head", 64 Tags: true, 65 } 66 got := Commands(args) 67 want := []string{ 68 "git init", 69 "git remote add origin https://github.com/octocat/hello-world.git", 70 "git fetch --depth=50 --tags origin +refs/heads/master:", 71 "git checkout master", 72 "git fetch origin refs/pull/42/head:", 73 "git merge --no-ff 3650a5d21bbf086fa8d2f16b0067ddeecfa604df", 74 } 75 if diff := cmp.Diff(got, want); diff != "" { 76 t.Log(want) 77 t.Fail() 78 t.Log(diff) 79 } 80 }