github.com/drone/runner-go@v1.12.0/environ/provider/util_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 provider 6 7 import ( 8 "testing" 9 10 "github.com/google/go-cmp/cmp" 11 ) 12 13 func TestToMap(t *testing.T) { 14 in := []*Variable{ 15 { 16 Name: "foo", 17 Data: "bar", 18 }, 19 } 20 want := map[string]string{ 21 "foo": "bar", 22 } 23 got := ToMap(in) 24 if diff := cmp.Diff(want, got); diff != "" { 25 t.Log(diff) 26 t.Errorf("Unexpected map value") 27 } 28 } 29 30 func TestFromMap(t *testing.T) { 31 in := map[string]string{ 32 "foo": "bar", 33 } 34 want := []*Variable{ 35 { 36 Name: "foo", 37 Data: "bar", 38 }, 39 } 40 got := ToSlice(in) 41 if diff := cmp.Diff(want, got); diff != "" { 42 t.Log(diff) 43 t.Errorf("Unexpected variable list") 44 } 45 } 46 47 func TestFilterMasked(t *testing.T) { 48 in := []*Variable{ 49 { 50 Name: "foo", 51 Data: "bar", 52 Mask: false, 53 }, 54 { 55 Name: "baz", 56 Data: "qux", 57 Mask: true, 58 }, 59 } 60 want := in[1:] 61 got := FilterMasked(in) 62 if diff := cmp.Diff(want, got); diff != "" { 63 t.Log(diff) 64 t.Errorf("Unexpected variable list") 65 } 66 } 67 68 func TestFilterUnmasked(t *testing.T) { 69 in := []*Variable{ 70 { 71 Name: "foo", 72 Data: "bar", 73 Mask: true, 74 }, 75 { 76 Name: "baz", 77 Data: "qux", 78 Mask: false, 79 }, 80 } 81 want := in[1:] 82 got := FilterUnmasked(in) 83 if diff := cmp.Diff(want, got); diff != "" { 84 t.Log(diff) 85 t.Errorf("Unexpected variable list") 86 } 87 }