github.com/drone/runner-go@v1.12.0/manifest/lookup_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package manifest 6 7 import "testing" 8 9 type resourceImpl struct { 10 Name, Kind, Type, Version string 11 } 12 13 func (r *resourceImpl) GetVersion() string { return r.Version } 14 func (r *resourceImpl) GetKind() string { return r.Kind } 15 func (r *resourceImpl) GetType() string { return r.Type } 16 func (r *resourceImpl) GetName() string { return r.Name } 17 18 func TestLookup(t *testing.T) { 19 want := &resourceImpl{Name: "default"} 20 m := &Manifest{ 21 Resources: []Resource{want}, 22 } 23 got, err := Lookup("default", m) 24 if err != nil { 25 t.Error(err) 26 } 27 if got != want { 28 t.Errorf("Expect resource not found error") 29 } 30 } 31 32 func TestLookupNotFound(t *testing.T) { 33 m := &Manifest{ 34 Resources: []Resource{ 35 &Secret{ 36 Kind: "secret", 37 Name: "password", 38 }, 39 }, 40 } 41 _, err := Lookup("default", m) 42 if err == nil { 43 t.Errorf("Expect resource not found error") 44 } 45 } 46 47 func TestNameMatch(t *testing.T) { 48 tests := []struct { 49 a, b string 50 match bool 51 }{ 52 {"a", "b", false}, 53 {"a", "a", true}, 54 {"", "default", true}, 55 } 56 for _, test := range tests { 57 got, want := isNameMatch(test.a, test.b), test.match 58 if got != want { 59 t.Errorf("Expect %q and %q match is %v", test.a, test.b, want) 60 } 61 } 62 }