github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/sidecar/run_test.go (about) 1 /* 2 Copyright 2017 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 sidecar 18 19 import ( 20 "testing" 21 22 "k8s.io/test-infra/prow/kube" 23 ) 24 25 func TestGetRevisionFromRef(t *testing.T) { 26 var tests = []struct { 27 name string 28 refs *kube.Refs 29 expected string 30 }{ 31 { 32 name: "Refs with Pull", 33 refs: &kube.Refs{ 34 BaseRef: "master", 35 BaseSHA: "deadbeef", 36 Pulls: []kube.Pull{ 37 { 38 Number: 123, 39 SHA: "abcd1234", 40 }, 41 }, 42 }, 43 expected: "abcd1234", 44 }, 45 { 46 name: "Refs with BaseSHA", 47 refs: &kube.Refs{ 48 BaseRef: "master", 49 BaseSHA: "deadbeef", 50 }, 51 expected: "deadbeef", 52 }, 53 { 54 name: "Refs with BaseRef", 55 refs: &kube.Refs{ 56 BaseRef: "master", 57 }, 58 expected: "master", 59 }, 60 } 61 62 for _, test := range tests { 63 if actual, expected := getRevisionFromRef(test.refs), test.expected; actual != expected { 64 t.Errorf("%s: got revision:%s but expected: %s", test.name, actual, expected) 65 } 66 } 67 }