github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/harness/downgrader/option_test.go (about) 1 // Copyright 2022 Harness, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package downgrader 16 17 import "testing" 18 19 func TestOptions(t *testing.T) { 20 p := New( 21 WithCodebase("drone", "connector.github"), 22 WithDockerhub("account.docker"), 23 WithKubernetes("namespace", "connector.kubernetes"), 24 WithIdentifier("foo"), 25 WithName("bar"), 26 WithOrganization("baz"), 27 WithProject("qux"), 28 ) 29 if got, want := p.codebaseConn, "connector.github"; got != want { 30 t.Errorf("Want codebase connector %q, got %q", want, got) 31 } 32 if got, want := p.codebaseName, "drone"; got != want { 33 t.Errorf("Want codebase name %q, got %q", want, got) 34 } 35 if got, want := p.kubeConnector, "connector.kubernetes"; got != want { 36 t.Errorf("Want kubernetes connector %q, got %q", want, got) 37 } 38 if got, want := p.kubeNamespace, "namespace"; got != want { 39 t.Errorf("Want kubernetes namespace %q, got %q", want, got) 40 } 41 if got, want := p.kubeEnabled, true; got != want { 42 t.Errorf("Want kubernetes enabled %v, got %v", want, got) 43 } 44 if got, want := p.dockerhubConn, "account.docker"; got != want { 45 t.Errorf("Want docker connector %q, got %q", want, got) 46 } 47 if got, want := p.pipelineId, "foo"; got != want { 48 t.Errorf("Want pipeline id %q, got %q", want, got) 49 } 50 if got, want := p.pipelineName, "bar"; got != want { 51 t.Errorf("Want pipeline name %q, got %q", want, got) 52 } 53 if got, want := p.pipelineOrg, "baz"; got != want { 54 t.Errorf("Want pipeline org %q, got %q", want, got) 55 } 56 if got, want := p.pipelineProj, "qux"; got != want { 57 t.Errorf("Want pipeline project %q, got %q", want, got) 58 } 59 } 60 61 func TestOptions_Defaults(t *testing.T) { 62 p := New() 63 64 if got, want := p.kubeConnector, ""; got != want { 65 t.Errorf("Want kubernetes connector %q, got %q", want, got) 66 } 67 if got, want := p.kubeNamespace, "default"; got != want { 68 t.Errorf("Want kubernetes namespace %q, got %q", want, got) 69 } 70 if got, want := p.kubeEnabled, false; got != want { 71 t.Errorf("Want kubernetes enabled %v, got %v", want, got) 72 } 73 if got, want := p.dockerhubConn, ""; got != want { 74 t.Errorf("Want docker connector %q, got %q", want, got) 75 } 76 if got, want := p.pipelineName, "default"; got != want { 77 t.Errorf("Want pipeline name %q, got %q", want, got) 78 } 79 if got, want := p.pipelineId, "default"; got != want { 80 t.Errorf("Want pipeline id %q, got %q", want, got) 81 } 82 if got, want := p.pipelineOrg, "default"; got != want { 83 t.Errorf("Want pipeline org %q, got %q", want, got) 84 } 85 if got, want := p.pipelineProj, "default"; got != want { 86 t.Errorf("Want pipeline project %q, got %q", want, got) 87 } 88 }