github.com/drone/runner-go@v1.12.0/environ/provider/combine_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  	"errors"
     9  	"testing"
    10  
    11  	"github.com/google/go-cmp/cmp"
    12  )
    13  
    14  func TestCombine(t *testing.T) {
    15  	a := map[string]string{"a": "b"}
    16  	b := map[string]string{"c": "d"}
    17  	aa := Static(a)
    18  	bb := Static(b)
    19  	p := Combine(aa, bb)
    20  	got, err := p.List(noContext, nil)
    21  	if err != nil {
    22  		t.Error(err)
    23  		return
    24  	}
    25  	if len(got) != 2 {
    26  		t.Errorf("Expect combined variable output")
    27  		return
    28  	}
    29  	want := []*Variable{
    30  		{
    31  			Name: "a",
    32  			Data: "b",
    33  			Mask: false,
    34  		},
    35  		{
    36  			Name: "c",
    37  			Data: "d",
    38  			Mask: false,
    39  		},
    40  	}
    41  	if diff := cmp.Diff(got, want); diff != "" {
    42  		t.Errorf(diff)
    43  	}
    44  }
    45  
    46  func TestCombineError(t *testing.T) {
    47  	e := errors.New("not found")
    48  	m := mockProvider{err: e}
    49  	p := Combine(&m)
    50  	_, err := p.List(noContext, nil)
    51  	if err != e {
    52  		t.Errorf("Expect error")
    53  	}
    54  }