github.com/YousefHaggyHeroku/pack@v1.5.5/internal/stack/merge_test.go (about)

     1  package stack_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sclevine/spec"
     7  	"github.com/sclevine/spec/report"
     8  
     9  	"github.com/YousefHaggyHeroku/pack/internal/dist"
    10  	"github.com/YousefHaggyHeroku/pack/internal/stack"
    11  	h "github.com/YousefHaggyHeroku/pack/testhelpers"
    12  )
    13  
    14  func TestMerge(t *testing.T) {
    15  	spec.Run(t, "testMerge", testMerge, spec.Parallel(), spec.Report(report.Terminal{}))
    16  }
    17  
    18  func testMerge(t *testing.T, when spec.G, it spec.S) {
    19  	when("MergeCompatible", func() {
    20  		when("a stack has more mixins than the other", func() {
    21  			it("add mixins", func() {
    22  				result := stack.MergeCompatible(
    23  					[]dist.Stack{{ID: "stack1", Mixins: []string{"build:mixinA", "mixinB", "run:mixinC"}}},
    24  					[]dist.Stack{{ID: "stack1", Mixins: []string{"build:mixinA", "run:mixinC"}}},
    25  				)
    26  
    27  				h.AssertEq(t, len(result), 1)
    28  				h.AssertEq(t, result, []dist.Stack{{ID: "stack1", Mixins: []string{"build:mixinA", "mixinB", "run:mixinC"}}})
    29  			})
    30  		})
    31  
    32  		when("stacks don't match id", func() {
    33  			it("returns no stacks", func() {
    34  				result := stack.MergeCompatible(
    35  					[]dist.Stack{{ID: "stack1", Mixins: []string{"build:mixinA", "mixinB", "run:mixinC"}}},
    36  					[]dist.Stack{{ID: "stack2", Mixins: []string{"build:mixinA", "run:mixinC"}}},
    37  				)
    38  
    39  				h.AssertEq(t, len(result), 0)
    40  			})
    41  		})
    42  
    43  		when("a set of stacks has extra stacks", func() {
    44  			it("removes extra stacks", func() {
    45  				result := stack.MergeCompatible(
    46  					[]dist.Stack{{ID: "stack1"}},
    47  					[]dist.Stack{
    48  						{ID: "stack1"},
    49  						{ID: "stack2"},
    50  					},
    51  				)
    52  
    53  				h.AssertEq(t, len(result), 1)
    54  				h.AssertEq(t, result, []dist.Stack{{ID: "stack1"}})
    55  			})
    56  		})
    57  	})
    58  }