github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/util/lookuptable/name_from_guid_test.go (about)

     1  package lookuptable_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/util/lookuptable"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  )
     8  
     9  var _ = Describe("NameFromGuid", func() {
    10  	It("builds a lookup table", func() {
    11  		input := []struct{ Name, GUID string }{
    12  			{Name: "foo-name", GUID: "foo-guid"},
    13  			{Name: "bar-name", GUID: "bar-guid"},
    14  			{Name: "baz-name", GUID: "baz-guid"},
    15  			{Name: "quz-name", GUID: "quz-guid"},
    16  		}
    17  
    18  		Expect(lookuptable.NameFromGUID(input)).To(Equal(map[string]string{
    19  			"foo-guid": "foo-name",
    20  			"bar-guid": "bar-name",
    21  			"baz-guid": "baz-name",
    22  			"quz-guid": "quz-name",
    23  		}))
    24  	})
    25  
    26  	When("the input is not a slice", func() {
    27  		It("returns nil", func() {
    28  			input := struct{ Name, GUID string }{
    29  				Name: "foo-name",
    30  				GUID: "foo-guid",
    31  			}
    32  
    33  			Expect(lookuptable.NameFromGUID(input)).To(BeNil())
    34  		})
    35  	})
    36  
    37  	When("the elements are not structs", func() {
    38  		It("returns nil", func() {
    39  			input := []string{"foo", "bar"}
    40  			Expect(lookuptable.NameFromGUID(input)).To(BeNil())
    41  		})
    42  	})
    43  })