github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/internal/orbs/codecov/codecov_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 codecov 16 17 import ( 18 "strings" 19 "testing" 20 21 circle "github.com/drone/go-convert/convert/circle/yaml" 22 harness "github.com/drone/spec/dist/go" 23 24 "github.com/google/go-cmp/cmp" 25 ) 26 27 func TestUpload(t *testing.T) { 28 in := &circle.Custom{ 29 Params: map[string]interface{}{}, 30 } 31 32 got := Convert("upload", in) 33 want := &harness.Step{ 34 Name: "codecov", 35 Type: "script", 36 Spec: &harness.StepExec{ 37 Run: strings.Join( 38 []string{ 39 "curl -Os https://uploader.codecov.io/latest/linux/codecov", 40 "chmod +x codecov", 41 "./codecov -t -n $DRONE_BUILD_NUMBER", 42 }, "\n", 43 ), 44 }, 45 } 46 47 if diff := cmp.Diff(got, want); diff != "" { 48 t.Errorf("Unexpected orb conversion") 49 t.Log(diff) 50 } 51 } 52 53 func TestUploadParams(t *testing.T) { 54 in := &circle.Custom{ 55 Params: map[string]interface{}{ 56 "upload_name": "latest", 57 "token": "TOPSECRET", 58 }, 59 } 60 61 got := Convert("upload", in) 62 want := &harness.Step{ 63 Name: "codecov", 64 Type: "script", 65 Spec: &harness.StepExec{ 66 Run: strings.Join( 67 []string{ 68 "curl -Os https://uploader.codecov.io/latest/linux/codecov", 69 "chmod +x codecov", 70 "./codecov -t TOPSECRET -n latest", 71 }, "\n", 72 ), 73 }, 74 } 75 76 if diff := cmp.Diff(got, want); diff != "" { 77 t.Errorf("Unexpected orb conversion") 78 t.Log(diff) 79 } 80 } 81 82 func TestUnknownCommand(t *testing.T) { 83 if Convert("unknown", nil) != nil { 84 t.Errorf("Expect unknown command returns nil step") 85 } 86 }