From 7747e62b570b8b68aaa27bea315a0810556ac03e Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Tue, 23 Apr 2019 21:12:44 +0200 Subject: [PATCH] Fixing tests --- cmd/drone-agent/health_test.go | 12 +++-- cncd/pipeline/pipec/exec.go | 12 ++++- cncd/pipeline/pipec/exec_test.go | 2 +- .../backend/kubernetes/volumes_test.go | 49 +------------------ 4 files changed, 20 insertions(+), 55 deletions(-) diff --git a/cmd/drone-agent/health_test.go b/cmd/drone-agent/health_test.go index fbe23593f..1f0124f90 100644 --- a/cmd/drone-agent/health_test.go +++ b/cmd/drone-agent/health_test.go @@ -17,11 +17,13 @@ package main import ( "testing" "time" + + "github.com/laszlocph/drone-oss-08/runner" ) func TestHealthy(t *testing.T) { - s := state{} - s.Metadata = map[string]info{} + s := runner.State{} + s.Metadata = map[string]runner.Info{} s.Add("1", time.Hour, "octocat/hello-world", "42") @@ -35,7 +37,7 @@ func TestHealthy(t *testing.T) { t.Errorf("got repository name %s, want %s", got, want) } - s.Metadata["1"] = info{ + s.Metadata["1"] = runner.Info{ Timeout: time.Hour, Started: time.Now().UTC(), } @@ -43,14 +45,14 @@ func TestHealthy(t *testing.T) { t.Error("want healthy status when timeout not exceeded, got false") } - s.Metadata["1"] = info{ + s.Metadata["1"] = runner.Info{ Started: time.Now().UTC().Add(-(time.Minute * 30)), } if s.Healthy() == false { t.Error("want healthy status when timeout+buffer not exceeded, got false") } - s.Metadata["1"] = info{ + s.Metadata["1"] = runner.Info{ Started: time.Now().UTC().Add(-(time.Hour + time.Minute)), } if s.Healthy() == true { diff --git a/cncd/pipeline/pipec/exec.go b/cncd/pipeline/pipec/exec.go index 192f2e629..8d3456227 100644 --- a/cncd/pipeline/pipec/exec.go +++ b/cncd/pipeline/pipec/exec.go @@ -40,6 +40,16 @@ var executeCommand = cli.Command{ EnvVar: "CI_KUBERNETES_NAMESPACE", Value: "default", }, + cli.StringFlag{ + EnvVar: "CI_KUBERNETES_STORAGECLASS", + Name: "storageclass", + Value: "local-storage", + }, + cli.StringFlag{ + EnvVar: "CI_KUBERNETES_VOLUME_SIZE", + Name: "volumesize", + Value: "100Mi", + }, cli.StringFlag{ Name: "kubernetes-endpoint", EnvVar: "CI_KUBERNETES_ENDPOINT", @@ -75,7 +85,7 @@ func executeAction(c *cli.Context) (err error) { var engine backend.Engine if c.Bool("kubernetes") { - engine, err = kubernetes.New() + engine, err = kubernetes.New(c.String("kubernetes-namespace"), c.String("storageclass"), c.String("volumesize")) if err != nil { return err } diff --git a/cncd/pipeline/pipec/exec_test.go b/cncd/pipeline/pipec/exec_test.go index 35afb453c..379e8f0d8 100644 --- a/cncd/pipeline/pipec/exec_test.go +++ b/cncd/pipeline/pipec/exec_test.go @@ -59,7 +59,7 @@ func TestKubeExec(t *testing.T) { } // os.Setenv("KUBECONFIG", "/etc/rancher/k3s/k3s.yaml") - engine, err := kubernetes.New() + engine, err := kubernetes.New("default", "local-storage", "100Mi") if err != nil { t.Errorf("Could not start Kubernetes engine %f", err) } diff --git a/cncd/pipeline/pipeline/backend/kubernetes/volumes_test.go b/cncd/pipeline/pipeline/backend/kubernetes/volumes_test.go index d2a1c1807..5f7b91918 100644 --- a/cncd/pipeline/pipeline/backend/kubernetes/volumes_test.go +++ b/cncd/pipeline/pipeline/backend/kubernetes/volumes_test.go @@ -7,53 +7,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPersistentVolume(t *testing.T) { - expected := ` - { - "metadata": { - "name": "someName", - "namespace": "someNamespace", - "creationTimestamp": null - }, - "spec": { - "capacity": { - "storage": "1Gi" - }, - "local": { - "path": "/tmp" - }, - "accessModes": [ - "ReadWriteMany" - ], - "persistentVolumeReclaimPolicy": "Retain", - "storageClassName": "local-storage", - "nodeAffinity": { - "required": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "kubernetes.io/hostname", - "operator": "In", - "values": [ - "someNode" - ] - } - ] - } - ] - } - } - }, - "status": {} - }` - - pv := PersistentVolume("someNode", "someNamespace", "someName") - j, err := json.Marshal(pv) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(j)) -} - func TestPersistentVolumeClaim(t *testing.T) { expected := ` { @@ -76,7 +29,7 @@ func TestPersistentVolumeClaim(t *testing.T) { "status": {} }` - pvc := PersistentVolumeClaim("someNamespace", "someName") + pvc := PersistentVolumeClaim("someNamespace", "someName", "local-storage", "1Gi") j, err := json.Marshal(pvc) assert.Nil(t, err) assert.JSONEq(t, expected, string(j))