feat: allow replacing buildpack list atomically
Add buildpacks:set --replace so callers can replace an app's complete ordered buildpack list in one command while preserving existing single-buildpack and --index behavior. Closes #8802
This commit is contained in:
6 files changed
+205
-4
No files matched your search
@@ -139,3 +139,79 @@ func TestGetBuildpacksAppJSONEmptyArray(t *testing.T) {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buildpacks).To(BeEmpty())
|
||||
}
|
||||
|
||||
func TestSetBuildpackListReplacesEntireList(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
tmpDir := setupTestEnvironment(t)
|
||||
defer teardownTestEnvironment(tmpDir)
|
||||
|
||||
propDir := filepath.Join(tmpDir, "config", "buildpacks", "test-app")
|
||||
Expect(os.MkdirAll(propDir, 0755)).To(Succeed())
|
||||
Expect(os.WriteFile(filepath.Join(propDir, "buildpacks"), []byte("https://github.com/heroku/heroku-buildpack-nodejs.git\nhttps://github.com/heroku/heroku-buildpack-python.git\nhttps://github.com/heroku/heroku-buildpack-ruby.git\n"), 0644)).To(Succeed())
|
||||
|
||||
err := setBuildpackList("test-app", []string{"heroku/ruby", "heroku/nodejs"}, 0)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
buildpacks, err := getBuildpacks("test-app")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buildpacks).To(HaveLen(2))
|
||||
Expect(buildpacks[0]).To(Equal("https://github.com/heroku/heroku-buildpack-ruby.git"))
|
||||
Expect(buildpacks[1]).To(Equal("https://github.com/heroku/heroku-buildpack-nodejs.git"))
|
||||
}
|
||||
|
||||
func TestSetBuildpackListSingleBuildpack(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
tmpDir := setupTestEnvironment(t)
|
||||
defer teardownTestEnvironment(tmpDir)
|
||||
|
||||
propDir := filepath.Join(tmpDir, "config", "buildpacks", "test-app")
|
||||
Expect(os.MkdirAll(propDir, 0755)).To(Succeed())
|
||||
Expect(os.WriteFile(filepath.Join(propDir, "buildpacks"), []byte("https://github.com/heroku/heroku-buildpack-nodejs.git\nhttps://github.com/heroku/heroku-buildpack-python.git\n"), 0644)).To(Succeed())
|
||||
|
||||
err := setBuildpackList("test-app", []string{"heroku/ruby"}, 0)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
buildpacks, err := getBuildpacks("test-app")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buildpacks).To(HaveLen(1))
|
||||
Expect(buildpacks[0]).To(Equal("https://github.com/heroku/heroku-buildpack-ruby.git"))
|
||||
}
|
||||
|
||||
func TestSetBuildpackListInvalidLeavesListUnchanged(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
tmpDir := setupTestEnvironment(t)
|
||||
defer teardownTestEnvironment(tmpDir)
|
||||
|
||||
propDir := filepath.Join(tmpDir, "config", "buildpacks", "test-app")
|
||||
Expect(os.MkdirAll(propDir, 0755)).To(Succeed())
|
||||
Expect(os.WriteFile(filepath.Join(propDir, "buildpacks"), []byte("https://github.com/heroku/heroku-buildpack-nodejs.git\n"), 0644)).To(Succeed())
|
||||
|
||||
err := setBuildpackList("test-app", []string{"heroku/ruby", "nodejs"}, 0)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("Invalid buildpack specified"))
|
||||
|
||||
buildpacks, err := getBuildpacks("test-app")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buildpacks).To(HaveLen(1))
|
||||
Expect(buildpacks[0]).To(Equal("https://github.com/heroku/heroku-buildpack-nodejs.git"))
|
||||
}
|
||||
|
||||
func TestSetBuildpackListRejectsIndex(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
tmpDir := setupTestEnvironment(t)
|
||||
defer teardownTestEnvironment(tmpDir)
|
||||
|
||||
err := setBuildpackList("test-app", []string{"heroku/ruby"}, 1)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("--index"))
|
||||
}
|
||||
|
||||
func TestSetBuildpackListRejectsEmpty(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
tmpDir := setupTestEnvironment(t)
|
||||
defer teardownTestEnvironment(tmpDir)
|
||||
|
||||
err := setBuildpackList("test-app", []string{}, 0)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("buildpacks:clear"))
|
||||
}
|
||||
Reference in new issue
Block a user