github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/util_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 circle 16 17 import "testing" 18 19 func TestSplitOrb(t *testing.T) { 20 tests := []struct { 21 name string 22 alias string 23 command string 24 }{ 25 { 26 name: "node/install", 27 alias: "node", 28 command: "install", 29 }, 30 { 31 name: "node", 32 alias: "node", 33 command: "", 34 }, 35 } 36 for _, test := range tests { 37 alias, command := splitOrb(test.name) 38 if got, want := alias, test.alias; got != want { 39 t.Errorf("Got alias %s want %s", got, want) 40 } 41 if got, want := command, test.command; got != want { 42 t.Errorf("Got command %s want %s", got, want) 43 } 44 } 45 } 46 47 func TestSplitOrbVersion(t *testing.T) { 48 tests := []struct { 49 name string 50 alias string 51 version string 52 }{ 53 { 54 name: "node@1.0.0", 55 alias: "node", 56 version: "1.0.0", 57 }, 58 { 59 name: "node", 60 alias: "node", 61 version: "", 62 }, 63 } 64 for _, test := range tests { 65 alias, command := splitOrbVersion(test.name) 66 if got, want := alias, test.alias; got != want { 67 t.Errorf("Got alias %s want %s", got, want) 68 } 69 if got, want := command, test.version; got != want { 70 t.Errorf("Got version %s want %s", got, want) 71 } 72 } 73 }