github.com/drone/runner-go@v1.12.0/internal/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 internal 6 7 import ( 8 "testing" 9 10 "github.com/drone/drone-go/drone" 11 12 "github.com/google/go-cmp/cmp" 13 ) 14 15 func TestCloneRepo(t *testing.T) { 16 src := &drone.Repo{ 17 ID: 1, 18 UID: "2", 19 UserID: 3, 20 Namespace: "octocat", 21 Name: "hello-world", 22 Slug: "octocat/hello-world", 23 SCM: "git", 24 HTTPURL: "https://github.com/octocat/hello-world.git", 25 SSHURL: "git@github.com:octocat/hello-world.git", 26 Link: "https://github.com/octocat/hello-world", 27 Branch: "master", 28 Private: true, 29 Visibility: "public", 30 Active: true, 31 Config: ".drone.yml", 32 Trusted: true, 33 Protected: true, 34 IgnoreForks: true, 35 IgnorePulls: true, 36 Timeout: 60, 37 Counter: 50, 38 Synced: 1561256365, 39 Created: 1561256505, 40 Updated: 1561256511, 41 Version: 1, 42 } 43 dst := CloneRepo(src) 44 if src == dst { 45 t.Errorf("Except copy of repo, got reference") 46 } 47 if diff := cmp.Diff(src, dst); diff != "" { 48 t.Errorf("Expect copy of values") 49 t.Log(diff) 50 } 51 } 52 53 func TestCloneBuild(t *testing.T) { 54 src := &drone.Build{ 55 ID: 1, 56 RepoID: 2, 57 Number: 3, 58 Parent: 4, 59 Status: drone.StatusFailing, 60 Error: "", 61 Event: drone.EventPush, 62 Action: "created", 63 Link: "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", 64 Timestamp: 1561256041, 65 Title: "", 66 Message: "updated README", 67 Before: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e", 68 After: "762941318ee16e59dabbacb1b4049eec22f0d303", 69 Ref: "refs/heads/master", 70 Fork: "spaceghost/hello-world", 71 Source: "develop", 72 Target: "master", 73 Author: "octocat", 74 AuthorName: "The Octocat", 75 AuthorEmail: "octocat@github.com", 76 AuthorAvatar: "https://avatars2.githubusercontent.com/u/251370", 77 Sender: "spaceghost", 78 Params: map[string]string{"memory": "high"}, 79 Cron: "nightly", 80 Deploy: "production", 81 Started: 1561256065, 82 Finished: 1561256082, 83 Created: 1561256050, 84 Updated: 1561256052, 85 Version: 1, 86 Stages: []*drone.Stage{ 87 { 88 ID: 1, 89 BuildID: 2, 90 Number: 3, 91 Name: "build", 92 Kind: "pipeline", 93 Type: "docker", 94 Status: drone.StatusPassing, 95 Error: "", 96 ErrIgnore: true, 97 ExitCode: 0, 98 Machine: "server1", 99 OS: "linux", 100 Arch: "amd64", 101 Variant: "", 102 Kernel: "", 103 Limit: 0, 104 Started: 1561256065, 105 Stopped: 1561256505, 106 Created: 1561256356, 107 Updated: 1561256082, 108 Version: 1, 109 OnSuccess: true, 110 OnFailure: true, 111 DependsOn: []string{"clone"}, 112 Labels: map[string]string{"foo": "bar"}, 113 }, 114 }, 115 } 116 dst := CloneBuild(src) 117 if src == dst { 118 t.Errorf("Except copy of build, got reference") 119 } 120 if diff := cmp.Diff(src, dst); diff != "" { 121 t.Errorf("Expect copy of values") 122 t.Log(diff) 123 } 124 125 if src.Stages[0] == dst.Stages[0] { 126 t.Errorf("Except copy of stages, got reference") 127 } 128 if diff := cmp.Diff(src.Stages[0], dst.Stages[0]); diff != "" { 129 t.Errorf("Expect copy of stage values") 130 t.Log(diff) 131 } 132 } 133 134 func TestCloneStage(t *testing.T) { 135 src := &drone.Stage{ 136 ID: 1, 137 BuildID: 2, 138 Number: 3, 139 Name: "build", 140 Kind: "pipeline", 141 Type: "docker", 142 Status: drone.StatusPassing, 143 Error: "", 144 ErrIgnore: true, 145 ExitCode: 0, 146 Machine: "server1", 147 OS: "linux", 148 Arch: "amd64", 149 Variant: "", 150 Kernel: "", 151 Limit: 0, 152 Started: 1561256065, 153 Stopped: 1561256505, 154 Created: 1561256356, 155 Updated: 1561256082, 156 Version: 1, 157 OnSuccess: true, 158 OnFailure: true, 159 DependsOn: []string{"clone"}, 160 Labels: map[string]string{"foo": "bar"}, 161 Steps: []*drone.Step{ 162 { 163 ID: 1, 164 StageID: 2, 165 Number: 3, 166 Name: "foo", 167 Status: drone.StatusFailing, 168 Error: "", 169 ErrIgnore: false, 170 ExitCode: 255, 171 Started: 1561256065, 172 Stopped: 1561256082, 173 Version: 1, 174 }, 175 }, 176 } 177 dst := CloneStage(src) 178 if src == dst { 179 t.Errorf("Except copy of stage, got reference") 180 } 181 if src.Steps[0] == dst.Steps[0] { 182 t.Errorf("Except copy of step, got reference") 183 } 184 if diff := cmp.Diff(src, dst); diff != "" { 185 t.Errorf("Expect copy of step values") 186 t.Log(diff) 187 } 188 if diff := cmp.Diff(src.Steps[0], dst.Steps[0]); diff != "" { 189 t.Errorf("Expect copy of stage values") 190 t.Log(diff) 191 } 192 } 193 194 func TestCloneStep(t *testing.T) { 195 src := &drone.Step{ 196 ID: 1, 197 StageID: 2, 198 Number: 3, 199 Name: "foo", 200 Status: drone.StatusFailing, 201 Error: "", 202 ErrIgnore: false, 203 ExitCode: 255, 204 Started: 1561256065, 205 Stopped: 1561256082, 206 Version: 1, 207 } 208 dst := CloneStep(src) 209 if src == dst { 210 t.Errorf("Except copy of step, got reference") 211 } 212 if diff := cmp.Diff(src, dst); diff != "" { 213 t.Errorf("Expect copy of values") 214 t.Log(diff) 215 } 216 dst.ID = 101 217 dst.StageID = 102 218 dst.Number = 103 219 dst.Name = "bar" 220 dst.ErrIgnore = true 221 dst.ExitCode = 0 222 dst.Status = drone.StatusPassing 223 dst.Started = 1561256356 224 dst.Stopped = 1561256365 225 dst.Version = 2 226 if diff := cmp.Diff(src, dst); diff == "" { 227 t.Errorf("Expect copy of values, got reference") 228 } 229 }