github.com/drone/runner-go@v1.12.0/clone/utils_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 "testing" 8 9 func TestFetchFlags(t *testing.T) { 10 var args Args 11 if got, want := fetchFlags(args), ""; got != want { 12 t.Errorf("Want %q, got %q", want, got) 13 } 14 args.Tags = true 15 if got, want := fetchFlags(args), "--tags"; got != want { 16 t.Errorf("Want %q, got %q", want, got) 17 } 18 args.Tags = false 19 args.Depth = 50 20 if got, want := fetchFlags(args), "--depth=50"; got != want { 21 t.Errorf("Want %q, got %q", want, got) 22 } 23 } 24 25 func TestMergeFlags(t *testing.T) { 26 var args Args 27 if got, want := mergeFlags(args), ""; got != want { 28 t.Errorf("Want %q, got %q", want, got) 29 } 30 args.NoFF = true 31 if got, want := mergeFlags(args), "--no-ff"; got != want { 32 t.Errorf("Want %q, got %q", want, got) 33 } 34 } 35 36 func TestIsTag(t *testing.T) { 37 tests := []struct { 38 s string 39 v bool 40 }{ 41 { 42 s: "refs/heads/master", 43 v: false, 44 }, 45 { 46 s: "refs/pull/1/head", 47 v: false, 48 }, 49 { 50 s: "refs/tags/v1.0.0", 51 v: true, 52 }, 53 } 54 55 for _, test := range tests { 56 if got, want := isTag(test.s), test.v; got != want { 57 t.Errorf("Want tag %v for %s", want, test.s) 58 } 59 } 60 } 61 62 func TestIsPullRequst(t *testing.T) { 63 tests := []struct { 64 s string 65 v bool 66 }{ 67 { 68 s: "refs/heads/master", 69 v: false, 70 }, 71 { 72 s: "refs/pull/1/head", 73 v: true, 74 }, 75 { 76 s: "refs/pull/2/merge", 77 v: true, 78 }, 79 } 80 81 for _, test := range tests { 82 if got, want := isPullRequest(test.s), test.v; got != want { 83 t.Errorf("Want pull request %v for %s", want, test.s) 84 } 85 } 86 }