github.com/YousefHaggyHeroku/pack@v1.5.5/internal/builder/descriptor_test.go (about)

     1  package builder_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/buildpacks/lifecycle/api"
     7  	"github.com/heroku/color"
     8  	"github.com/sclevine/spec"
     9  	"github.com/sclevine/spec/report"
    10  
    11  	"github.com/YousefHaggyHeroku/pack/internal/builder"
    12  	h "github.com/YousefHaggyHeroku/pack/testhelpers"
    13  )
    14  
    15  func TestDescriptor(t *testing.T) {
    16  	color.Disable(true)
    17  	defer color.Disable(false)
    18  	spec.Run(t, "Builder", testDescriptor, spec.Parallel(), spec.Report(report.Terminal{}))
    19  }
    20  
    21  func testDescriptor(t *testing.T, when spec.G, it spec.S) {
    22  	when("CompatDescriptor", func() {
    23  		when("missing apis", func() {
    24  			it("makes a lifecycle from a blob", func() {
    25  				descriptor := builder.CompatDescriptor(builder.LifecycleDescriptor{
    26  					Info: builder.LifecycleInfo{},
    27  					API: builder.LifecycleAPI{
    28  						BuildpackVersion: api.MustParse("0.2"),
    29  						PlatformVersion:  api.MustParse("0.3"),
    30  					},
    31  				})
    32  
    33  				h.AssertEq(t, descriptor.API.BuildpackVersion.String(), "0.2")
    34  				h.AssertEq(t, descriptor.API.PlatformVersion.String(), "0.3")
    35  
    36  				// fill supported with deprecated field
    37  				h.AssertEq(t, descriptor.APIs.Buildpack.Deprecated.AsStrings(), []string{})
    38  				h.AssertEq(t, descriptor.APIs.Buildpack.Supported.AsStrings(), []string{"0.2"})
    39  				h.AssertEq(t, descriptor.APIs.Platform.Deprecated.AsStrings(), []string{})
    40  				h.AssertEq(t, descriptor.APIs.Platform.Supported.AsStrings(), []string{"0.3"})
    41  			})
    42  		})
    43  
    44  		when("missing api", func() {
    45  			it("sets lowest value supported", func() {
    46  				descriptor := builder.CompatDescriptor(builder.LifecycleDescriptor{
    47  					APIs: builder.LifecycleAPIs{
    48  						Buildpack: builder.APIVersions{
    49  							Supported: builder.APISet{api.MustParse("0.2"), api.MustParse("0.3")},
    50  						},
    51  						Platform: builder.APIVersions{
    52  							Supported: builder.APISet{api.MustParse("1.2"), api.MustParse("2.3")},
    53  						},
    54  					},
    55  				})
    56  
    57  				h.AssertEq(t, descriptor.APIs.Buildpack.Deprecated.AsStrings(), []string{})
    58  				h.AssertEq(t, descriptor.APIs.Buildpack.Supported.AsStrings(), []string{"0.2", "0.3"})
    59  				h.AssertEq(t, descriptor.APIs.Platform.Deprecated.AsStrings(), []string{})
    60  				h.AssertEq(t, descriptor.APIs.Platform.Supported.AsStrings(), []string{"1.2", "2.3"})
    61  
    62  				// select lowest value for deprecated parameters
    63  				h.AssertEq(t, descriptor.API.BuildpackVersion.String(), "0.2")
    64  				h.AssertEq(t, descriptor.API.PlatformVersion.String(), "1.2")
    65  			})
    66  
    67  			it("sets lowest value supported + deprecated", func() {
    68  				descriptor := builder.CompatDescriptor(builder.LifecycleDescriptor{
    69  					APIs: builder.LifecycleAPIs{
    70  						Buildpack: builder.APIVersions{
    71  							Deprecated: builder.APISet{api.MustParse("0.1")},
    72  							Supported:  builder.APISet{api.MustParse("0.2"), api.MustParse("0.3")},
    73  						},
    74  						Platform: builder.APIVersions{
    75  							Deprecated: builder.APISet{api.MustParse("1.1")},
    76  							Supported:  builder.APISet{api.MustParse("1.2"), api.MustParse("2.3")},
    77  						},
    78  					},
    79  				})
    80  
    81  				h.AssertEq(t, descriptor.APIs.Buildpack.Deprecated.AsStrings(), []string{"0.1"})
    82  				h.AssertEq(t, descriptor.APIs.Buildpack.Supported.AsStrings(), []string{"0.2", "0.3"})
    83  				h.AssertEq(t, descriptor.APIs.Platform.Deprecated.AsStrings(), []string{"1.1"})
    84  				h.AssertEq(t, descriptor.APIs.Platform.Supported.AsStrings(), []string{"1.2", "2.3"})
    85  
    86  				// select lowest value for deprecated parameters
    87  				h.AssertEq(t, descriptor.API.BuildpackVersion.String(), "0.1")
    88  				h.AssertEq(t, descriptor.API.PlatformVersion.String(), "1.1")
    89  			})
    90  		})
    91  
    92  		when("missing api + apis", func() {
    93  			it("makes a lifecycle from a blob", func() {
    94  				descriptor := builder.CompatDescriptor(builder.LifecycleDescriptor{})
    95  
    96  				h.AssertNil(t, descriptor.API.BuildpackVersion)
    97  				h.AssertNil(t, descriptor.API.PlatformVersion)
    98  
    99  				// fill supported with deprecated field
   100  				h.AssertEq(t, descriptor.APIs.Buildpack.Deprecated.AsStrings(), []string{})
   101  				h.AssertEq(t, descriptor.APIs.Buildpack.Supported.AsStrings(), []string{})
   102  				h.AssertEq(t, descriptor.APIs.Platform.Deprecated.AsStrings(), []string{})
   103  				h.AssertEq(t, descriptor.APIs.Platform.Supported.AsStrings(), []string{})
   104  			})
   105  		})
   106  	})
   107  
   108  	when("Earliest", func() {
   109  		it("returns lowest value", func() {
   110  			h.AssertEq(
   111  				t,
   112  				builder.APISet{api.MustParse("2.1"), api.MustParse("0.1"), api.MustParse("1.1")}.Earliest().String(),
   113  				"0.1",
   114  			)
   115  		})
   116  	})
   117  
   118  	when("Latest", func() {
   119  		it("returns highest value", func() {
   120  			h.AssertEq(
   121  				t,
   122  				builder.APISet{api.MustParse("1.1"), api.MustParse("2.1"), api.MustParse("0.1")}.Latest().String(),
   123  				"2.1",
   124  			)
   125  		})
   126  	})
   127  }