github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/creds/secret_var_lookup_test.go (about)

     1  package creds_test
     2  
     3  import (
     4  	"github.com/pf-qiu/concourse/v6/atc/creds"
     5  	"github.com/pf-qiu/concourse/v6/atc/creds/dummy"
     6  	"github.com/pf-qiu/concourse/v6/vars"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("VariableLookupFromSecrets", func() {
    13  	var (
    14  		variables vars.Variables
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		secrets := dummy.NewSecretsFactory([]dummy.VarFlag{
    19  			{
    20  				Name: "a",
    21  				Value: map[string]interface{}{
    22  					"b": map[interface{}]interface{}{
    23  						"c": "foo",
    24  					},
    25  				},
    26  			},
    27  		}).NewSecrets()
    28  		variables = creds.NewVariables(secrets, "team", "pipeline", true)
    29  	})
    30  
    31  	Describe("Get", func() {
    32  		It("traverses fields", func() {
    33  			result, found, err := variables.Get(vars.Reference{Path: "a", Fields: []string{"b", "c"}})
    34  			Expect(err).NotTo(HaveOccurred())
    35  			Expect(found).To(BeTrue())
    36  
    37  			Expect(result).To(Equal("foo"))
    38  		})
    39  
    40  		Context("when a field is missing", func() {
    41  			It("errors", func() {
    42  				_, _, err := variables.Get(vars.Reference{Path: "a", Fields: []string{"b", "d"}})
    43  				Expect(err).To(HaveOccurred())
    44  			})
    45  		})
    46  	})
    47  })