Skip to content

Commit

Permalink
Fix acceptance tests
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Romero <[email protected]>
  • Loading branch information
jromero committed Aug 11, 2020
1 parent 611189c commit bf53027
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
80 changes: 35 additions & 45 deletions acceptance/config/asset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"regexp"
"testing"

"github.com/buildpacks/lifecycle/api"

acceptanceOS "github.com/buildpacks/pack/acceptance/os"
"github.com/buildpacks/pack/internal/blob"
"github.com/buildpacks/pack/internal/builder"
Expand All @@ -27,7 +25,6 @@ const (
var (
currentPackFixturesDir = filepath.Join("testdata", "pack_fixtures")
previousPackFixturesOverridesDir = filepath.Join("testdata", "pack_previous_fixtures_overrides")
githubAssetFetcher *GithubAssetFetcher
lifecycleTgzExp = regexp.MustCompile(`lifecycle-v\d+.\d+.\d+\+linux.x86-64.tgz`)
)

Expand All @@ -36,6 +33,7 @@ type AssetManager struct {
packFixturesPath string
previousPackPath string
previousPackFixturesPaths []string
githubAssetFetcher *GithubAssetFetcher
lifecyclePath string
lifecycleDescriptor builder.LifecycleDescriptor
previousLifecyclePath string
Expand All @@ -58,10 +56,14 @@ func ConvergedAssetManager(t *testing.T, assert h.AssertionManager, inputConfig
convergedDefaultLifecycleDescriptor builder.LifecycleDescriptor
)

githubAssetFetcher, err := NewGithubAssetFetcher(t, inputConfig.githubToken)
h.AssertNil(t, err)

assetBuilder := assetManagerBuilder{
testObject: t,
assert: assert,
inputConfig: inputConfig,
testObject: t,
assert: assert,
inputConfig: inputConfig,
githubAssetFetcher: githubAssetFetcher,
}

if inputConfig.combinations.requiresCurrentPack() {
Expand All @@ -84,7 +86,7 @@ func ConvergedAssetManager(t *testing.T, assert h.AssertionManager, inputConfig
}

if inputConfig.combinations.requiresDefaultLifecycle() {
convergedDefaultLifecycleDescriptor = defaultLifecycleDescriptor()
convergedDefaultLifecycleDescriptor = assetBuilder.defaultLifecycleDescriptor()
}

return AssetManager{
Expand Down Expand Up @@ -151,9 +153,10 @@ func (a AssetManager) LifecycleDescriptor(kind ComboValue) builder.LifecycleDesc
}

type assetManagerBuilder struct {
testObject *testing.T
assert h.AssertionManager
inputConfig InputConfigurationManager
testObject *testing.T
assert h.AssertionManager
inputConfig InputConfigurationManager
githubAssetFetcher *GithubAssetFetcher
}

func (b assetManagerBuilder) ensureCurrentPack() string {
Expand Down Expand Up @@ -184,11 +187,10 @@ func (b assetManagerBuilder) ensurePreviousPack() string {
style.Symbol(envPreviousPackPath),
)

b.ensureGithubAssetFetcher()
version, err := githubAssetFetcher.FetchReleaseVersion("buildpacks", "pack", 0)
version, err := b.githubAssetFetcher.FetchReleaseVersion("buildpacks", "pack", 0)
b.assert.Nil(err)

assetDir, err := githubAssetFetcher.FetchReleaseAsset(
assetDir, err := b.githubAssetFetcher.FetchReleaseAsset(
"buildpacks",
"pack",
version,
Expand Down Expand Up @@ -216,11 +218,10 @@ func (b assetManagerBuilder) ensurePreviousPackFixtures() string {
style.Symbol(envPreviousPackFixturesPath),
)

b.ensureGithubAssetFetcher()
version, err := githubAssetFetcher.FetchReleaseVersion("buildpacks", "pack", 0)
version, err := b.githubAssetFetcher.FetchReleaseVersion("buildpacks", "pack", 0)
b.assert.Nil(err)

sourceDir, err := githubAssetFetcher.FetchReleaseSource("buildpacks", "pack", version)
sourceDir, err := b.githubAssetFetcher.FetchReleaseSource("buildpacks", "pack", version)
b.assert.Nil(err)

sourceDirFiles, err := ioutil.ReadDir(sourceDir)
Expand All @@ -246,9 +247,9 @@ func (b assetManagerBuilder) ensureCurrentLifecycle() (string, builder.Lifecycle
style.Symbol(envLifecyclePath),
)

lifecyclePath = b.downloadLifecycle(0)
lifecyclePath = b.downloadLifecycleRelative(0)

b.testObject.Logf("using %s for default lifecycle path", lifecyclePath)
b.testObject.Logf("using %s for current lifecycle path", lifecyclePath)
}

lifecycle, err := builder.NewLifecycle(blob.NewBlob(lifecyclePath))
Expand All @@ -269,7 +270,7 @@ func (b assetManagerBuilder) ensurePreviousLifecycle() (string, builder.Lifecycl
style.Symbol(envPreviousLifecyclePath),
)

previousLifecyclePath = b.downloadLifecycle(-1)
previousLifecyclePath = b.downloadLifecycleRelative(-1)

b.testObject.Logf("using %s for previous lifecycle path", previousLifecyclePath)
}
Expand All @@ -280,15 +281,8 @@ func (b assetManagerBuilder) ensurePreviousLifecycle() (string, builder.Lifecycl
return previousLifecyclePath, lifecycle.Descriptor()
}

func (b assetManagerBuilder) downloadLifecycle(relativeVersion int) string {
b.testObject.Helper()

b.ensureGithubAssetFetcher()

version, err := githubAssetFetcher.FetchReleaseVersion("buildpacks", "lifecycle", relativeVersion)
b.assert.Nil(err)

path, err := githubAssetFetcher.FetchReleaseAsset(
func (b assetManagerBuilder) downloadLifecycle(version string) string {
path, err := b.githubAssetFetcher.FetchReleaseAsset(
"buildpacks",
"lifecycle",
version,
Expand All @@ -300,16 +294,13 @@ func (b assetManagerBuilder) downloadLifecycle(relativeVersion int) string {
return path
}

func (b assetManagerBuilder) ensureGithubAssetFetcher() {
func (b assetManagerBuilder) downloadLifecycleRelative(relativeVersion int) string {
b.testObject.Helper()

if githubAssetFetcher != nil {
return
}

var err error
githubAssetFetcher, err = NewGithubAssetFetcher(b.testObject, b.inputConfig.githubToken)
version, err := b.githubAssetFetcher.FetchReleaseVersion("buildpacks", "lifecycle", relativeVersion)
b.assert.Nil(err)

return b.downloadLifecycle(version)
}

func (b assetManagerBuilder) buildPack(compileVersion string) string {
Expand Down Expand Up @@ -339,14 +330,13 @@ func (b assetManagerBuilder) buildPack(compileVersion string) string {
return packPath
}

func defaultLifecycleDescriptor() builder.LifecycleDescriptor {
return builder.CompatDescriptor(builder.LifecycleDescriptor{
Info: builder.LifecycleInfo{
Version: builder.VersionMustParse(builder.DefaultLifecycleVersion),
},
API: builder.LifecycleAPI{
BuildpackVersion: api.MustParse(builder.DefaultBuildpackAPIVersion),
PlatformVersion: api.MustParse(builder.DefaultPlatformAPIVersion),
},
})
func (b assetManagerBuilder) defaultLifecycleDescriptor() builder.LifecycleDescriptor {
lifecyclePath := b.downloadLifecycle("v" + builder.DefaultLifecycleVersion)

b.testObject.Logf("using %s for default lifecycle path", lifecyclePath)

lifecycle, err := builder.NewLifecycle(blob.NewBlob(lifecyclePath))
b.assert.Nil(err)

return lifecycle.Descriptor()
}
4 changes: 2 additions & 2 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
gomock.Any(),
"https://github.com/buildpacks/lifecycle/releases/download/v3.4.5/lifecycle-v3.4.5+windows.x86-64.tgz",
).Return(
blob.NewBlob(filepath.Join("testdata", "lifecycle")), nil,
blob.NewBlob(filepath.Join("testdata", "lifecycle", "platform-0.4")), nil,
)

err = packClientWithExperimental.CreateBuilder(context.TODO(), opts)
Expand Down Expand Up @@ -483,7 +483,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
builder.DefaultLifecycleVersion,
),
).Return(
blob.NewBlob(filepath.Join("testdata", "lifecycle")), nil,
blob.NewBlob(filepath.Join("testdata", "lifecycle", "platform-0.4")), nil,
)

err = packClientWithExperimental.CreateBuilder(context.TODO(), opts)
Expand Down
1 change: 0 additions & 1 deletion internal/builder/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
const (
DefaultLifecycleVersion = "0.9.0"
DefaultBuildpackAPIVersion = "0.2"
DefaultPlatformAPIVersion = "0.3"
)

// Blob is an interface to wrap opening blobs
Expand Down

0 comments on commit bf53027

Please sign in to comment.