github.com/cloudfoundry/libcfbuildpack@v1.91.23/layers/touched_layers_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 layers_test
    18  
    19  import (
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"github.com/cloudfoundry/libcfbuildpack/layers"
    24  	"github.com/cloudfoundry/libcfbuildpack/logger"
    25  	"github.com/cloudfoundry/libcfbuildpack/test"
    26  	"github.com/onsi/gomega"
    27  	"github.com/sclevine/spec"
    28  	"github.com/sclevine/spec/report"
    29  )
    30  
    31  func TestTouchedLayers(t *testing.T) {
    32  	spec.Run(t, "TouchedLayers", func(t *testing.T, _ spec.G, it spec.S) {
    33  
    34  		g := gomega.NewWithT(t)
    35  
    36  		var (
    37  			root    string
    38  			touched layers.TouchedLayers
    39  		)
    40  
    41  		it.Before(func() {
    42  			root = test.ScratchDir(t, "touched-layers")
    43  			touched = layers.NewTouchedLayers(root, logger.Logger{})
    44  		})
    45  
    46  		it("does not remove touched layers", func() {
    47  			test.TouchFile(t, root, "test-layer.toml")
    48  
    49  			touched.Add(filepath.Join(root, "test-layer.toml"))
    50  			g.Expect(touched.Cleanup()).To(gomega.Succeed())
    51  
    52  			g.Expect(filepath.Join(root, "test-layer.toml")).To(gomega.BeARegularFile())
    53  		})
    54  
    55  		it("removes untouched layers", func() {
    56  			test.TouchFile(t, root, "test-layer.toml")
    57  
    58  			g.Expect(touched.Cleanup()).To(gomega.Succeed())
    59  
    60  			g.Expect(filepath.Join(root, "test-layer.toml")).NotTo(gomega.BeARegularFile())
    61  		})
    62  
    63  		it("does not remove launch.toml", func() {
    64  			test.TouchFile(t, root, "launch.toml")
    65  
    66  			g.Expect(touched.Cleanup()).To(gomega.Succeed())
    67  
    68  			g.Expect(filepath.Join(root, "launch.toml")).To(gomega.BeARegularFile())
    69  		})
    70  
    71  		it("does not remove store.toml", func() {
    72  			test.TouchFile(t, root, "store.toml")
    73  
    74  			g.Expect(touched.Cleanup()).To(gomega.Succeed())
    75  
    76  			g.Expect(filepath.Join(root, "store.toml")).To(gomega.BeARegularFile())
    77  		})
    78  	}, spec.Report(report.Terminal{}))
    79  }