github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/acceptance/assertions/lifecycle_output.go (about) 1 //go:build acceptance 2 // +build acceptance 3 4 package assertions 5 6 import ( 7 "fmt" 8 "regexp" 9 "strings" 10 "testing" 11 12 h "github.com/buildpacks/pack/testhelpers" 13 ) 14 15 type LifecycleOutputAssertionManager struct { 16 testObject *testing.T 17 assert h.AssertionManager 18 output string 19 } 20 21 func NewLifecycleOutputAssertionManager(t *testing.T, output string) LifecycleOutputAssertionManager { 22 return LifecycleOutputAssertionManager{ 23 testObject: t, 24 assert: h.NewAssertionManager(t), 25 output: output, 26 } 27 } 28 29 func (l LifecycleOutputAssertionManager) ReportsRestoresCachedLayer(layer string) { 30 l.testObject.Helper() 31 l.testObject.Log("restores the cache") 32 33 l.assert.MatchesAll( 34 l.output, 35 regexp.MustCompile(fmt.Sprintf(`(?i)Restoring data for "%s" from cache`, layer)), 36 regexp.MustCompile(fmt.Sprintf(`(?i)Restoring metadata for "%s" from app image`, layer)), 37 ) 38 } 39 40 func (l LifecycleOutputAssertionManager) ReportsExporterReusingUnchangedLayer(layer string) { 41 l.testObject.Helper() 42 l.testObject.Log("exporter reuses unchanged layers") 43 44 l.assert.Matches(l.output, regexp.MustCompile(fmt.Sprintf(`(?i)Reusing layer '%s'`, layer))) 45 } 46 47 func (l LifecycleOutputAssertionManager) ReportsCacheReuse(layer string) { 48 l.testObject.Helper() 49 l.testObject.Log("cacher reuses unchanged layers") 50 51 l.assert.Matches(l.output, regexp.MustCompile(fmt.Sprintf(`(?i)Reusing cache layer '%s'`, layer))) 52 } 53 54 func (l LifecycleOutputAssertionManager) ReportsCacheCreation(layer string) { 55 l.testObject.Helper() 56 l.testObject.Log("cacher adds layers") 57 58 l.assert.Matches(l.output, regexp.MustCompile(fmt.Sprintf(`(?i)Adding cache layer '%s'`, layer))) 59 } 60 61 func (l LifecycleOutputAssertionManager) ReportsSkippingBuildpackLayerAnalysis() { 62 l.testObject.Helper() 63 l.testObject.Log("skips buildpack layer analysis") 64 65 l.assert.Matches(l.output, regexp.MustCompile(`(?i)Skipping buildpack layer analysis`)) 66 } 67 68 func (l LifecycleOutputAssertionManager) IncludesSeparatePhases() { 69 l.testObject.Helper() 70 71 l.assert.ContainsAll(l.output, "[detector]", "[analyzer]", "[builder]", "[exporter]") 72 } 73 74 func (l LifecycleOutputAssertionManager) IncludesSeparatePhasesWithBuildExtension() { 75 l.testObject.Helper() 76 77 // Earlier pack versions print `[extender]`, later pack versions print `[extender (build)]`. 78 // Removing the `]` for the extend phase allows us to navigate compat suite complexity without undo headache. 79 // When previous pack is old enough, we can make the matcher more precise. 80 l.assert.ContainsAll(l.output, "[detector]", "[analyzer]", "[extender", "[exporter]") 81 } 82 83 func (l LifecycleOutputAssertionManager) IncludesSeparatePhasesWithRunExtension() { 84 l.testObject.Helper() 85 86 l.assert.ContainsAll(l.output, "[detector]", "[analyzer]", "[extender (run)]", "[exporter]") 87 } 88 89 func (l LifecycleOutputAssertionManager) IncludesTagOrEphemeralLifecycle(tag string) { 90 l.testObject.Helper() 91 92 if !strings.Contains(l.output, tag) { 93 if !strings.Contains(l.output, "pack.local/lifecyle") { 94 l.testObject.Fatalf("Unable to locate reference to lifecycle image within output") 95 } 96 } 97 }