From 5873d01aa139e0f001efccca3c5b0b435d3bbbc5 Mon Sep 17 00:00:00 2001 From: pat-s Date: Tue, 7 Jan 2025 11:34:30 +0100 Subject: [PATCH] tests --- pipeline/backend/docker/convert_test.go | 4 +-- pipeline/backend/kubernetes/pod_test.go | 38 ++++++++++----------- pipeline/backend/kubernetes/secrets_test.go | 4 +-- pipeline/backend/kubernetes/service_test.go | 12 +++---- pipeline/backend/kubernetes/utils_test.go | 8 ++--- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pipeline/backend/docker/convert_test.go b/pipeline/backend/docker/convert_test.go index 180aa1aa8..6118f3490 100644 --- a/pipeline/backend/docker/convert_test.go +++ b/pipeline/backend/docker/convert_test.go @@ -97,7 +97,7 @@ func TestSplitVolumeParts(t *testing.T) { var ( testCmdStep = &backend.Step{ Name: "hello", - UUID: "f51821af-4cb8-435e-a3c2-3a684185d828", + UUID: "f5182", Type: backend.StepTypeCommands, Commands: []string{"echo \"hello world\"", "ls"}, Image: "alpine", @@ -106,7 +106,7 @@ var ( testPluginStep = &backend.Step{ Name: "lint", - UUID: "d841ee40-e66e-4275-bb3f-55bf89744b21", + UUID: "d841e", Type: backend.StepTypePlugin, Image: "mstruebing/editorconfig-checker", Environment: make(map[string]string), diff --git a/pipeline/backend/kubernetes/pod_test.go b/pipeline/backend/kubernetes/pod_test.go index 60961cf2c..e68603979 100644 --- a/pipeline/backend/kubernetes/pod_test.go +++ b/pipeline/backend/kubernetes/pod_test.go @@ -26,9 +26,9 @@ import ( ) func TestPodName(t *testing.T) { - name, err := podName(&types.Step{UUID: "01he8bebctabr3kgk0qj36d2me-0", Name: "go-test"}, "workflowNameTest") + name, err := podName(&types.Step{UUID: "01he8-0", Name: "go-test"}, "workflowNameTest") assert.NoError(t, err) - assert.Equal(t, "wp-workflownametest-go-test-01he8", name) + assert.Equal(t, "wp-workflownametest-go-test-01he8-0", name) _, err = podName(&types.Step{UUID: "01\\he8bebctabr3kgk0qj36d2me\\0a"}, "workflowNameTest") assert.ErrorContains(t, err, "name is not a valid kubernetes DNS name") @@ -38,19 +38,19 @@ func TestPodName(t *testing.T) { } func TestStepToPodName(t *testing.T) { - name, err := stepToPodName(&types.Step{UUID: "01he8bebctabr3kg", Name: "clone", Type: types.StepTypeClone}, "workflowNameTest") + name, err := stepToPodName(&types.Step{UUID: "01he8", Name: "clone", Type: types.StepTypeClone}, "workflowNameTest") assert.NoError(t, err) assert.EqualValues(t, "wp-workflownametest-clone-01he8", name) - name, err = stepToPodName(&types.Step{UUID: "01he8bebctabr3kg", Name: "cache", Type: types.StepTypeCache}, "workflowNameTest") + name, err = stepToPodName(&types.Step{UUID: "01he8", Name: "cache", Type: types.StepTypeCache}, "workflowNameTest") assert.NoError(t, err) assert.EqualValues(t, "wp-workflownametest-cache-01he8", name) - name, err = stepToPodName(&types.Step{UUID: "01he8bebctabr3kg", Name: "release", Type: types.StepTypePlugin}, "workflowNameTest") + name, err = stepToPodName(&types.Step{UUID: "01he8", Name: "release", Type: types.StepTypePlugin}, "workflowNameTest") assert.NoError(t, err) assert.EqualValues(t, "wp-workflownametest-release-01he8", name) - name, err = stepToPodName(&types.Step{UUID: "01he8bebctabr3kg", Name: "prepare-env", Type: types.StepTypeCommands}, "workflowNameTest") + name, err = stepToPodName(&types.Step{UUID: "01he8", Name: "prepare-env", Type: types.StepTypeCommands}, "workflowNameTest") assert.NoError(t, err) assert.EqualValues(t, "wp-workflownametest-prepare-env-01he8", name) - name, err = stepToPodName(&types.Step{UUID: "01he8bebctabr3kg", Name: "postgres", Type: types.StepTypeService}, "workflowNameTest") + name, err = stepToPodName(&types.Step{UUID: "01he8", Name: "postgres", Type: types.StepTypeService}, "workflowNameTest") assert.NoError(t, err) assert.EqualValues(t, "wp-svc-workflownametest-postgres-01he8", name) } @@ -68,7 +68,7 @@ func TestTinyPod(t *testing.T) { const expected = ` { "metadata": { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "namespace": "woodpecker", "creationTimestamp": null, "labels": { @@ -86,7 +86,7 @@ func TestTinyPod(t *testing.T) { ], "containers": [ { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "image": "gradle:8.4.0-jdk21", "command": [ "/bin/sh", @@ -133,7 +133,7 @@ func TestTinyPod(t *testing.T) { Environment: map[string]string{"CI": "woodpecker"}, }, &config{ Namespace: "woodpecker", - }, "wp-workflownametest-go-test-01he8", "linux/amd64", BackendOptions{}, "workflowNameTest") + }, "wp-workflownametest-go-test-01he8-0", "linux/amd64", BackendOptions{}, "workflowNameTest") assert.NoError(t, err) podJSON, err := json.Marshal(pod) @@ -147,7 +147,7 @@ func TestFullPod(t *testing.T) { const expected = ` { "metadata": { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "namespace": "woodpecker", "creationTimestamp": null, "labels": { @@ -171,7 +171,7 @@ func TestFullPod(t *testing.T) { ], "containers": [ { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "image": "meltwater/drone-cache", "command": [ "/bin/sh", @@ -256,7 +256,7 @@ func TestFullPod(t *testing.T) { "name": "another-pull-secret" }, { - "name": "wp-workflownametest-go-test-01he8" + "name": "wp-workflownametest-go-test-01he8-0" } ], "tolerations": [ @@ -310,7 +310,7 @@ func TestFullPod(t *testing.T) { }, } pod, err := mkPod(&types.Step{ - UUID: "01he8bebctabr3kgk0qj36d2me-0", + UUID: "01he8-0", Name: "go-test", Image: "meltwater/drone-cache", WorkingDir: "/woodpecker/src", @@ -335,7 +335,7 @@ func TestFullPod(t *testing.T) { PodAnnotationsAllowFromStep: true, PodNodeSelector: map[string]string{"topology.kubernetes.io/region": "eu-central-1"}, SecurityContext: SecurityContextConfig{RunAsNonRoot: false}, - }, "wp-workflownametest-go-test-01he8", "linux/amd64", BackendOptions{ + }, "wp-workflownametest-go-test-01he8-0", "linux/amd64", BackendOptions{ Labels: map[string]string{"part-of": "woodpecker-ci"}, Annotations: map[string]string{"kubernetes.io/limit-ranger": "LimitRanger plugin set: cpu, memory request and limit for container"}, NodeSelector: map[string]string{"storage": "ssd"}, @@ -366,7 +366,7 @@ func TestPodPrivilege(t *testing.T) { }, &config{ Namespace: "woodpecker", SecurityContext: SecurityContextConfig{RunAsNonRoot: globalRunAsRoot}, - }, "wp-workflownametest-go-test-01he8", "linux/amd64", BackendOptions{ + }, "wp-workflownametest-go-test-01he8-0", "linux/amd64", BackendOptions{ SecurityContext: &secCtx, }, "workflowNameTest") } @@ -443,7 +443,7 @@ func TestScratchPod(t *testing.T) { const expected = ` { "metadata": { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "namespace": "woodpecker", "creationTimestamp": null, "labels": { @@ -453,7 +453,7 @@ func TestScratchPod(t *testing.T) { "spec": { "containers": [ { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "image": "quay.io/curl/curl", "command": [ "/usr/bin/curl", @@ -474,7 +474,7 @@ func TestScratchPod(t *testing.T) { Entrypoint: []string{"/usr/bin/curl", "-v", "google.com"}, }, &config{ Namespace: "woodpecker", - }, "wp-workflownametest-go-test-01he8", "linux/amd64", BackendOptions{}, "workflowNameTest") + }, "wp-workflownametest-go-test-01he8-0", "linux/amd64", BackendOptions{}, "workflowNameTest") assert.NoError(t, err) podJSON, err := json.Marshal(pod) diff --git a/pipeline/backend/kubernetes/secrets_test.go b/pipeline/backend/kubernetes/secrets_test.go index 4300b4d91..8e3c9398d 100644 --- a/pipeline/backend/kubernetes/secrets_test.go +++ b/pipeline/backend/kubernetes/secrets_test.go @@ -208,7 +208,7 @@ func TestUsernameAndPasswordNeedsSecret(t *testing.T) { func TestRegistrySecret(t *testing.T) { const expected = `{ "metadata": { - "name": "wp-workflownametest-go-test-01he8", + "name": "wp-workflownametest-go-test-01he8-0", "namespace": "woodpecker", "creationTimestamp": null, "labels": { @@ -222,7 +222,7 @@ func TestRegistrySecret(t *testing.T) { }` secret, err := mkRegistrySecret(&types.Step{ - UUID: "01he8bebctabr3kgk0qj36d2me-0", + UUID: "01he8-0", Name: "go-test", Image: "meltwater/drone-cache", AuthConfig: types.Auth{ diff --git a/pipeline/backend/kubernetes/service_test.go b/pipeline/backend/kubernetes/service_test.go index 338d35cfb..185c5a381 100644 --- a/pipeline/backend/kubernetes/service_test.go +++ b/pipeline/backend/kubernetes/service_test.go @@ -24,15 +24,15 @@ import ( ) func TestServiceName(t *testing.T) { - name, err := serviceName(&types.Step{Name: "database", UUID: "01he8bebctabr3kgk0qj36d2me"}, "workflowNameTest") + name, err := serviceName(&types.Step{Name: "database", UUID: "01he8"}, "workflowNameTest") assert.NoError(t, err) assert.Equal(t, "wp-svc-workflownametest-database-01he8", name) - name, err = serviceName(&types.Step{Name: "wp-workflownametest-clone-01he8-0-services-0.woodpecker-runtime.svc.cluster.local", UUID: "01he8bebctabr3kgk0qj36d2me"}, "workflowNameTest") + name, err = serviceName(&types.Step{Name: "wp-workflownametest-clone-01he8-0-services-0.woodpecker-runtime.svc.cluster.local", UUID: "01he8"}, "workflowNameTest") assert.NoError(t, err) assert.Equal(t, "wp-svc-workflownametest-wp-workflownametest-clone-01he8-0-services-0.woodpecker-runtime.svc.cluster.local-01he8", name) - name, err = serviceName(&types.Step{Name: "awesome_service", UUID: "01he8bebctabr3kgk0qj36d2me"}, "workflowNameTest") + name, err = serviceName(&types.Step{Name: "awesome_service", UUID: "01he8"}, "workflowNameTest") assert.NoError(t, err) assert.Equal(t, "wp-svc-workflownametest-awesome-service-01he8", name) } @@ -41,7 +41,7 @@ func TestService(t *testing.T) { expected := ` { "metadata": { - "name": "wp-svc-workflownametest-bar-01he8", + "name": "wp-svc-workflownametest-bar-01he8-0", "namespace": "foo", "creationTimestamp": null }, @@ -66,7 +66,7 @@ func TestService(t *testing.T) { } ], "selector": { - "service": "wp-svc-workflownametest-bar-01he8" + "service": "wp-svc-workflownametest-bar-01he8-0" }, "type": "ClusterIP" }, @@ -81,7 +81,7 @@ func TestService(t *testing.T) { } s, err := mkService(&types.Step{ Name: "bar", - UUID: "01he8bebctabr3kgk0qj36d2me-0", + UUID: "01he8-0", Ports: ports, }, &config{Namespace: "foo"}, "workflowNameTest") assert.NoError(t, err) diff --git a/pipeline/backend/kubernetes/utils_test.go b/pipeline/backend/kubernetes/utils_test.go index 7836ebb1f..17da4165f 100644 --- a/pipeline/backend/kubernetes/utils_test.go +++ b/pipeline/backend/kubernetes/utils_test.go @@ -21,17 +21,17 @@ import ( ) func TestDNSName(t *testing.T) { - name, err := dnsName("wp_01he8bebctabr3kgk0qj36d2me_0_services_0") + name, err := dnsName("wp_01he8_0_services_0") assert.NoError(t, err) - assert.Equal(t, "wp-01he8bebctabr3kgk0qj36d2me-0-services-0", name) + assert.Equal(t, "wp-01he8-0-services-0", name) name, err = dnsName("a.0-AA") assert.NoError(t, err) assert.Equal(t, "a.0-aa", name) - name, err = dnsName("wp-01he8bebctabr3kgk0qj36d2me-0-services-0.woodpecker-runtime.svc.cluster.local") + name, err = dnsName("wp-01he8-0-services-0.woodpecker-runtime.svc.cluster.local") assert.NoError(t, err) - assert.Equal(t, "wp-01he8bebctabr3kgk0qj36d2me-0-services-0.woodpecker-runtime.svc.cluster.local", name) + assert.Equal(t, "wp-01he8-0-services-0.woodpecker-runtime.svc.cluster.local", name) _, err = dnsName(".0-a") assert.ErrorContains(t, err, "name is not a valid kubernetes DNS name")