github.com/zntrio/harp/v2@v2.0.9/pkg/bundle/vault/internal/operation/exporter_test.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package operation 19 20 import ( 21 "testing" 22 ) 23 24 func Test_extractVersion(t *testing.T) { 25 type args struct { 26 packagePath string 27 } 28 tests := []struct { 29 name string 30 args args 31 want string 32 want1 uint32 33 wantErr bool 34 }{ 35 { 36 name: "blank", 37 wantErr: true, 38 }, 39 { 40 name: "no version", 41 args: args{ 42 packagePath: "app/test", 43 }, 44 wantErr: false, 45 want: "app/test", 46 want1: 0, 47 }, 48 { 49 name: "with version", 50 args: args{ 51 packagePath: "app/test?version=14", 52 }, 53 wantErr: false, 54 want: "app/test", 55 want1: 14, 56 }, 57 { 58 name: "with invalid version", 59 args: args{ 60 packagePath: "app/test?version=azerty", 61 }, 62 wantErr: true, 63 }, 64 { 65 name: "with invalid path", 66 args: args{ 67 packagePath: "\n\t", 68 }, 69 wantErr: true, 70 }, 71 } 72 for _, tt := range tests { 73 t.Run(tt.name, func(t *testing.T) { 74 got, got1, err := extractVersion(tt.args.packagePath) 75 if (err != nil) != tt.wantErr { 76 t.Errorf("exporter.extractVersion() error = %v, wantErr %v", err, tt.wantErr) 77 return 78 } 79 if got != tt.want { 80 t.Errorf("exporter.extractVersion() got = %v, want %v", got, tt.want) 81 } 82 if got1 != tt.want1 { 83 t.Errorf("exporter.extractVersion() got1 = %v, want %v", got1, tt.want1) 84 } 85 }) 86 } 87 }