github.com/BarDweller/libpak@v0.0.0-20230630201634-8dd5cfc15ec9/carton/build_image_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/BarDweller/libpak/carton" 29 ) 30 31 func testBuildImageDependency(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-image-dependency") 46 Expect(err).NotTo(HaveOccurred()) 47 48 _, err = f.WriteString(`test-prologue 49 build-image = "image-name:test-version-1" 50 test-epilogue 51 `) 52 Expect(err).To(Succeed()) 53 Expect(f.Close()).To(Succeed()) 54 path = f.Name() 55 }) 56 57 it.After(func() { 58 Expect(os.RemoveAll(path)).To(Succeed()) 59 }) 60 61 it("updates dependency", func() { 62 d := carton.BuildImageDependency{ 63 BuilderPath: path, 64 Version: "test-version-2", 65 } 66 67 d.Update(carton.WithExitHandler(exitHandler)) 68 69 Expect(os.ReadFile(path)).To(Equal([]byte(`test-prologue 70 build-image = "image-name:test-version-2" 71 test-epilogue 72 `))) 73 }) 74 }