initial commit [ci skip]
This commit is contained in:
126
engine/compiler/clone_test.go
Normal file
126
engine/compiler/clone_test.go
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package compiler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/drone-runners/drone-runner-docker/engine"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
)
|
||||
|
||||
func TestClone(t *testing.T) {
|
||||
random = notRandom
|
||||
defer func() {
|
||||
random = uniuri.New
|
||||
}()
|
||||
|
||||
c := &Compiler{
|
||||
Repo: &drone.Repo{},
|
||||
Build: &drone.Build{},
|
||||
Stage: &drone.Stage{},
|
||||
System: &drone.System{},
|
||||
Netrc: &drone.Netrc{},
|
||||
Manifest: &manifest.Manifest{},
|
||||
Pipeline: &resource.Pipeline{},
|
||||
}
|
||||
want := []*engine.Step{
|
||||
{
|
||||
ID: "random",
|
||||
Image: "drone/git:1",
|
||||
Name: "clone",
|
||||
RunPolicy: engine.RunAlways,
|
||||
WorkingDir: "/drone/src",
|
||||
},
|
||||
}
|
||||
got := c.Compile(nil)
|
||||
ignore := cmpopts.IgnoreFields(engine.Step{}, "Envs")
|
||||
if diff := cmp.Diff(got.Steps, want, ignore); len(diff) != 0 {
|
||||
t.Errorf(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneDisable(t *testing.T) {
|
||||
c := &Compiler{
|
||||
Repo: &drone.Repo{},
|
||||
Build: &drone.Build{},
|
||||
Stage: &drone.Stage{},
|
||||
System: &drone.System{},
|
||||
Netrc: &drone.Netrc{},
|
||||
Manifest: &manifest.Manifest{},
|
||||
Pipeline: &resource.Pipeline{Clone: manifest.Clone{Disable: true}},
|
||||
}
|
||||
got := c.Compile(nil)
|
||||
if len(got.Steps) != 0 {
|
||||
t.Errorf("Expect no clone step added when disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneCreate(t *testing.T) {
|
||||
want := &engine.Step{
|
||||
Name: "clone",
|
||||
Image: "drone/git:1",
|
||||
RunPolicy: engine.RunAlways,
|
||||
Envs: map[string]string{"PLUGIN_DEPTH": "50"},
|
||||
}
|
||||
src := &resource.Pipeline{Clone: manifest.Clone{Depth: 50}}
|
||||
got := createClone(src)
|
||||
if diff := cmp.Diff(got, want); len(diff) != 0 {
|
||||
t.Errorf(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneImage(t *testing.T) {
|
||||
tests := []struct {
|
||||
in manifest.Platform
|
||||
out string
|
||||
}{
|
||||
{
|
||||
in: manifest.Platform{},
|
||||
out: "drone/git:1",
|
||||
},
|
||||
{
|
||||
in: manifest.Platform{OS: "linux"},
|
||||
out: "drone/git:1",
|
||||
},
|
||||
{
|
||||
in: manifest.Platform{OS: "windows"},
|
||||
out: "drone/git:latest",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
got, want := cloneImage(test.in), test.out
|
||||
if got != want {
|
||||
t.Errorf("Want clone image %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneParams(t *testing.T) {
|
||||
params := cloneParams(manifest.Clone{})
|
||||
if len(params) != 0 {
|
||||
t.Errorf("Expect empty clone parameters")
|
||||
}
|
||||
params = cloneParams(manifest.Clone{Depth: 0})
|
||||
if len(params) != 0 {
|
||||
t.Errorf("Expect zero depth ignored")
|
||||
}
|
||||
params = cloneParams(manifest.Clone{Depth: 50, SkipVerify: true})
|
||||
if params["PLUGIN_DEPTH"] != "50" {
|
||||
t.Errorf("Expect clone depth 50")
|
||||
}
|
||||
if params["GIT_SSL_NO_VERIFY"] != "true" {
|
||||
t.Errorf("Expect GIT_SSL_NO_VERIFY is true")
|
||||
}
|
||||
if params["PLUGIN_SKIP_VERIFY"] != "true" {
|
||||
t.Errorf("Expect PLUGIN_SKIP_VERIFY is true")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user