github.com/paketo-buildpacks/libpak@v1.70.0/carton/lifecycle_dependency_test.go (about) 1 /* 2 * Copyright 2018-2020 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package carton_test 18 19 import ( 20 "os" 21 "testing" 22 23 "github.com/buildpacks/libcnb/mocks" 24 . "github.com/onsi/gomega" 25 "github.com/sclevine/spec" 26 "github.com/stretchr/testify/mock" 27 28 "github.com/paketo-buildpacks/libpak/carton" 29 ) 30 31 func testLifecycleDependency(t *testing.T, context spec.G, it spec.S) { 32 var ( 33 Expect = NewWithT(t).Expect 34 35 exitHandler *mocks.ExitHandler 36 path string 37 ) 38 39 it.Before(func() { 40 var err error 41 42 exitHandler = &mocks.ExitHandler{} 43 exitHandler.On("Error", mock.Anything) 44 45 f, err := os.CreateTemp("", "carton-builder-dependency") 46 Expect(err).NotTo(HaveOccurred()) 47 48 _, err = f.WriteString(`test-prologue 49 50 [lifecycle] 51 uri = "test-uri" 52 53 test-epilogue 54 `) 55 Expect(err).To(Succeed()) 56 Expect(f.Close()).To(Succeed()) 57 path = f.Name() 58 }) 59 60 it.After(func() { 61 Expect(os.RemoveAll(path)).To(Succeed()) 62 }) 63 64 it("updates dependency", func() { 65 d := carton.LifecycleDependency{ 66 BuilderPath: path, 67 Version: "test-version-3", 68 } 69 70 d.Update(carton.WithExitHandler(exitHandler)) 71 72 Expect(os.ReadFile(path)).To(Equal([]byte(`test-prologue 73 74 [lifecycle] 75 uri = "https://github.com/buildpacks/lifecycle/releases/download/vtest-version-3/lifecycle-vtest-version-3+linux.x86-64.tgz" 76 77 test-epilogue 78 `))) 79 }) 80 }