github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/github/links_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package github 18 19 import ( 20 "testing" 21 ) 22 23 func TestParseLinks(t *testing.T) { 24 var testcases = []struct { 25 data string 26 expected map[string]string 27 }{ 28 { 29 ``, 30 map[string]string{}, 31 }, 32 { 33 `<u>; rel="r"`, 34 map[string]string{"r": "u"}, 35 }, 36 { 37 `<u>; rel="r", <u2>; rel="r2"`, 38 map[string]string{"r": "u", "r2": "u2"}, 39 }, 40 { 41 `<u>;rel="r"`, 42 map[string]string{"r": "u"}, 43 }, 44 { 45 `<u>; rel="r"; other="o"`, 46 map[string]string{"r": "u"}, 47 }, 48 { 49 `<u>; rel="r",,`, 50 map[string]string{"r": "u"}, 51 }, 52 } 53 for _, tc := range testcases { 54 actual := parseLinks(tc.data) 55 if len(actual) != len(tc.expected) { 56 t.Errorf("lengths mismatch: %v and %v", actual, tc.expected) 57 } 58 for k, v := range tc.expected { 59 if av, ok := actual[k]; !ok { 60 t.Errorf("link not found: %s", k) 61 } else if av != v { 62 t.Errorf("link %s was %s but should have been %s", k, av, v) 63 } 64 } 65 } 66 }