Skip to content

Commit 0ef6bf0

Browse files
davewalterrizwanreza
authored andcommitted
Allows migrations-directory to be specified multiple times
[#151810891] Signed-off-by: Rizwan Reza <rreza@pivotal.io>
1 parent 987125b commit 0ef6bf0

9 files changed

Lines changed: 97 additions & 33 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some_migration

acceptance/help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Usage: kiln [options] bake [<args>]
2828
2929
Command Arguments:
3030
-rt, --release-tarball slice location of the release tarball
31-
-m, --migrations-directory string path to the migrations directory
31+
-m, --migrations-directory slice path to the migrations directory
3232
-cm, --content-migration slice location of the content migration file
3333
-bcm, --base-content-migration string location of the base content migration file
3434
-st, --stemcell-tarball string location of the stemcell tarball

acceptance/main_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ property_blueprints:
259259
"--release-tarball", cfReleaseTarball,
260260
"--stemcell-tarball", stemcellTarball,
261261
"--handcraft", handcraft,
262+
"--migrations-directory", "fixtures/extra-migrations",
262263
"--migrations-directory", "fixtures/migrations",
263264
"--version", "7.8.9-build.4",
264265
"--final-version", "7.8.9",
@@ -283,6 +284,7 @@ property_blueprints:
283284
var (
284285
archivedMigration1 io.ReadCloser
285286
archivedMigration2 io.ReadCloser
287+
archivedMigration3 io.ReadCloser
286288
)
287289

288290
for _, f := range zr.File {
@@ -295,6 +297,11 @@ property_blueprints:
295297
archivedMigration2, err = f.Open()
296298
Expect(err).NotTo(HaveOccurred())
297299
}
300+
301+
if f.Name == "migrations/v1/some_migration.js" {
302+
archivedMigration3, err = f.Open()
303+
Expect(err).NotTo(HaveOccurred())
304+
}
298305
}
299306

300307
contents, err := ioutil.ReadAll(archivedMigration1)
@@ -304,6 +311,10 @@ property_blueprints:
304311
contents, err = ioutil.ReadAll(archivedMigration2)
305312
Expect(err).NotTo(HaveOccurred())
306313
Expect(string(contents)).To(Equal("auth-enterprise-sso-migration\n"))
314+
315+
contents, err = ioutil.ReadAll(archivedMigration3)
316+
Expect(err).NotTo(HaveOccurred())
317+
Expect(string(contents)).To(Equal("some_migration\n"))
307318
})
308319

309320
It("logs the progress to stdout", func() {

builder/tile_writer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ func (w TileWriter) Write(metadataContents []byte, config commands.BakeConfig) e
8181
return err
8282
}
8383

84-
if config.MigrationsDirectory != "" {
85-
err = w.addMigrations(files, config.MigrationsDirectory)
86-
if err != nil {
87-
return err
84+
if len(config.MigrationDirectories) > 0 {
85+
for _, migrationsDir := range config.MigrationDirectories {
86+
err = w.addMigrations(files, migrationsDir)
87+
if err != nil {
88+
return err
89+
}
8890
}
8991
}
9092

builder/tile_writer_test.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var _ = Describe("TileWriter", func() {
4242
ProductName: "cool-product-name",
4343
FilenamePrefix: "cool-product-file",
4444
ReleaseTarballs: []string{"/some/path/release-1.tgz", "/some/path/release-2.tgz"},
45-
MigrationsDirectory: "/some/path/migrations",
45+
MigrationDirectories: []string{"/some/path/migrations", "/some/other/path/migrations"},
4646
ContentMigrations: []string{"/some/path/content-migration-1.yml", "/some/path/content-migration-2.yml"},
4747
BaseContentMigration: "/some/path/base-content-migration.yml",
4848
Version: "1.2.3-build.4",
@@ -59,9 +59,17 @@ var _ = Describe("TileWriter", func() {
5959
migrationInfo.IsDirReturns(false)
6060

6161
filesystem.WalkStub = func(root string, walkFn filepath.WalkFunc) error {
62-
walkFn("/some/path/migrations", dirInfo, nil)
63-
walkFn("/some/path/migrations/migration-1.js", migrationInfo, nil)
64-
walkFn("/some/path/migrations/migration-2.js", migrationInfo, nil)
62+
switch root {
63+
case "/some/path/migrations":
64+
walkFn("/some/path/migrations", dirInfo, nil)
65+
walkFn("/some/path/migrations/migration-1.js", migrationInfo, nil)
66+
walkFn("/some/path/migrations/migration-2.js", migrationInfo, nil)
67+
case "/some/other/path/migrations":
68+
walkFn("/some/other/path/migrations", dirInfo, nil)
69+
walkFn("/some/other/path/migrations/other-migration.js", migrationInfo, nil)
70+
default:
71+
return nil
72+
}
6573
return nil
6674
}
6775

@@ -75,6 +83,8 @@ var _ = Describe("TileWriter", func() {
7583
return NewBuffer(bytes.NewBuffer([]byte("migration-1"))), nil
7684
case "/some/path/migrations/migration-2.js":
7785
return NewBuffer(bytes.NewBuffer([]byte("migration-2"))), nil
86+
case "/some/other/path/migrations/other-migration.js":
87+
return NewBuffer(bytes.NewBuffer([]byte("other-migration"))), nil
7888
default:
7989
return nil, fmt.Errorf("open %s: no such file or directory", path)
8090
}
@@ -93,7 +103,7 @@ var _ = Describe("TileWriter", func() {
93103
Expect(zipper.SetPathCall.CallCount).To(Equal(1))
94104
Expect(zipper.SetPathCall.Receives.Path).To(Equal("cool-product-file-1.2.3-build.4.pivotal"))
95105

96-
Expect(zipper.AddCall.Calls).To(HaveLen(6))
106+
Expect(zipper.AddCall.Calls).To(HaveLen(7))
97107

98108
Expect(zipper.AddCall.Calls[0].Path).To(Equal(filepath.Join("content_migrations", "migrations.yml")))
99109
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[0].File)).Should(gbytes.Say("combined-content-migration-contents"))
@@ -107,11 +117,14 @@ var _ = Describe("TileWriter", func() {
107117
Expect(zipper.AddCall.Calls[3].Path).To(Equal(filepath.Join("migrations", "v1", "migration-2.js")))
108118
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[3].File)).Should(gbytes.Say("migration-2"))
109119

110-
Expect(zipper.AddCall.Calls[4].Path).To(Equal(filepath.Join("releases", "release-1.tgz")))
111-
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[4].File)).Should(gbytes.Say(release1Content))
120+
Expect(zipper.AddCall.Calls[4].Path).To(Equal(filepath.Join("migrations", "v1", "other-migration.js")))
121+
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[4].File)).Should(gbytes.Say("other-migration"))
122+
123+
Expect(zipper.AddCall.Calls[5].Path).To(Equal(filepath.Join("releases", "release-1.tgz")))
124+
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[5].File)).Should(gbytes.Say(release1Content))
112125

113-
Expect(zipper.AddCall.Calls[5].Path).To(Equal(filepath.Join("releases", "release-2.tgz")))
114-
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[5].File)).Should(gbytes.Say(release2Content))
126+
Expect(zipper.AddCall.Calls[6].Path).To(Equal(filepath.Join("releases", "release-2.tgz")))
127+
Eventually(gbytes.BufferReader(zipper.AddCall.Calls[6].File)).Should(gbytes.Say(release2Content))
115128

116129
Expect(zipper.CloseCall.CallCount).To(Equal(1))
117130

@@ -122,6 +135,7 @@ var _ = Describe("TileWriter", func() {
122135
"Adding metadata/cool-product-name.yml to .pivotal...",
123136
"Adding migrations/v1/migration-1.js to .pivotal...",
124137
"Adding migrations/v1/migration-2.js to .pivotal...",
138+
"Adding migrations/v1/other-migration.js to .pivotal...",
125139
"Adding releases/release-1.tgz to .pivotal...",
126140
"Adding releases/release-2.tgz to .pivotal...",
127141
"Calculated md5 sum: THIS-IS-THE-SUM",
@@ -140,7 +154,7 @@ var _ = Describe("TileWriter", func() {
140154
ProductName: "cool-product-name",
141155
FilenamePrefix: "cool-product-file",
142156
ReleaseTarballs: []string{"/some/path/release-1.tgz", "/some/path/release-2.tgz"},
143-
MigrationsDirectory: "",
157+
MigrationDirectories: []string{},
144158
ContentMigrations: []string{},
145159
BaseContentMigration: "",
146160
Version: "1.2.3-build.4",
@@ -177,7 +191,7 @@ var _ = Describe("TileWriter", func() {
177191
ProductName: "cool-product-name",
178192
FilenamePrefix: "cool-product-file",
179193
ReleaseTarballs: []string{"/some/path/release-1.tgz", "/some/path/release-2.tgz"},
180-
MigrationsDirectory: "/some/path/migrations",
194+
MigrationDirectories: []string{"/some/path/migrations"},
181195
ContentMigrations: []string{},
182196
BaseContentMigration: "",
183197
Version: "1.2.3-build.4",
@@ -250,9 +264,9 @@ var _ = Describe("TileWriter", func() {
250264
}
251265

252266
config := commands.BakeConfig{
253-
ReleaseTarballs: []string{"/some/path/release-1.tgz"},
254-
MigrationsDirectory: "/some/path/migrations",
255-
StubReleases: true,
267+
ReleaseTarballs: []string{"/some/path/release-1.tgz"},
268+
MigrationDirectories: []string{"/some/path/migrations"},
269+
StubReleases: true,
256270
}
257271

258272
err := tileWriter.Write([]byte{}, config)

commands/bake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ func (b Bake) parseArgs(args []string) (BakeConfig, error) {
8585
return config, errors.New("--output-dir is a required parameter")
8686
}
8787

88-
if config.MigrationsDirectory != "" && len(config.ContentMigrations) > 0 {
88+
if len(config.MigrationDirectories) > 0 && len(config.ContentMigrations) > 0 {
8989
return config, errors.New("cannot build a tile with content migrations and migrations")
9090
}
9191

9292
if len(config.ContentMigrations) > 0 && config.BaseContentMigration == "" {
9393
return config, errors.New("base content migration is required when content migrations are provided")
9494
}
9595

96-
if config.MigrationsDirectory != "" && config.BaseContentMigration != "" {
96+
if len(config.MigrationDirectories) > 0 && config.BaseContentMigration != "" {
9797
return config, errors.New("cannot build a tile with a base content migration and migrations")
9898
}
9999

commands/bake_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "github.com/pivotal-cf/jhanda/flags"
44

55
type BakeConfig struct {
66
ReleaseTarballs flags.StringSlice `short:"rt" long:"release-tarball" description:"location of the release tarball"`
7-
MigrationsDirectory string `short:"m" long:"migrations-directory" description:"path to the migrations directory"`
7+
MigrationDirectories flags.StringSlice `short:"m" long:"migrations-directory" description:"path to the migrations directory"`
88
ContentMigrations flags.StringSlice `short:"cm" long:"content-migration" description:"location of the content migration file"`
99
BaseContentMigration string `short:"bcm" long:"base-content-migration" description:"location of the base content migration file"`
1010
StemcellTarball string `short:"st" long:"stemcell-tarball" description:"location of the stemcell tarball"`

commands/bake_test.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,53 @@ var _ = Describe("bake", func() {
7070

7171
config := tileMaker.MakeArgsForCall(0)
7272
Expect(config).To(Equal(commands.BakeConfig{
73-
StemcellTarball: "some-stemcell-tarball",
74-
ReleaseTarballs: []string{"some-release-tarball", "some-other-release-tarball"},
75-
Handcraft: "some-handcraft",
76-
Version: "1.2.3-build.4",
77-
FinalVersion: "1.2.3",
78-
ProductName: "cool-product-name",
79-
FilenamePrefix: "cool-product-file",
80-
OutputDir: "some-output-dir",
81-
MigrationsDirectory: "some-migrations-directory",
73+
StemcellTarball: "some-stemcell-tarball",
74+
ReleaseTarballs: []string{"some-release-tarball", "some-other-release-tarball"},
75+
Handcraft: "some-handcraft",
76+
Version: "1.2.3-build.4",
77+
FinalVersion: "1.2.3",
78+
ProductName: "cool-product-name",
79+
FilenamePrefix: "cool-product-file",
80+
OutputDir: "some-output-dir",
81+
MigrationDirectories: []string{"some-migrations-directory"},
8282
}))
8383
})
84+
85+
Context("when the migration directory is specified multiple times", func() {
86+
It("builds the tile", func() {
87+
err := bake.Execute([]string{
88+
"--stemcell-tarball", "some-stemcell-tarball",
89+
"--release-tarball", "some-release-tarball",
90+
"--release-tarball", "some-other-release-tarball",
91+
"--migrations-directory", "some-migrations-directory",
92+
"--migrations-directory", "some-other-migrations-directory",
93+
"--handcraft", "some-handcraft",
94+
"--version", "1.2.3-build.4",
95+
"--final-version", "1.2.3",
96+
"--product-name", "cool-product-name",
97+
"--filename-prefix", "cool-product-file",
98+
"--output-dir", "some-output-dir",
99+
})
100+
101+
Expect(err).NotTo(HaveOccurred())
102+
Expect(tileMaker.MakeCallCount()).To(Equal(1))
103+
104+
config := tileMaker.MakeArgsForCall(0)
105+
Expect(config).To(Equal(commands.BakeConfig{
106+
StemcellTarball: "some-stemcell-tarball",
107+
ReleaseTarballs: []string{"some-release-tarball", "some-other-release-tarball"},
108+
Handcraft: "some-handcraft",
109+
Version: "1.2.3-build.4",
110+
FinalVersion: "1.2.3",
111+
ProductName: "cool-product-name",
112+
FilenamePrefix: "cool-product-file",
113+
OutputDir: "some-output-dir",
114+
MigrationDirectories: []string{"some-migrations-directory", "some-other-migrations-directory"},
115+
}))
116+
117+
})
118+
119+
})
84120
})
85121

86122
It("builds the tile", func() {

kiln/tile_maker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("TileMaker", func() {
3535
StemcellTarball: "some-stemcell-tarball",
3636
ReleaseTarballs: []string{"some-release-tarball", "some-other-release-tarball"},
3737
Handcraft: "some-handcraft",
38-
MigrationsDirectory: "some-migrations-directory",
38+
MigrationDirectories: []string{"some-migrations-directory"},
3939
BaseContentMigration: "some-base-content-migration",
4040
ContentMigrations: []string{"some-content-migration", "some-other-content-migration"},
4141
OutputDir: "some-output-dir",
@@ -97,7 +97,7 @@ stemcell_criteria:
9797
StemcellTarball: "some-stemcell-tarball",
9898
ReleaseTarballs: []string{"some-release-tarball", "some-other-release-tarball"},
9999
Handcraft: "some-handcraft",
100-
MigrationsDirectory: "some-migrations-directory",
100+
MigrationDirectories: []string{"some-migrations-directory"},
101101
BaseContentMigration: "some-base-content-migration",
102102
ContentMigrations: []string{"some-content-migration", "some-other-content-migration"},
103103
OutputDir: "some-output-dir",

0 commit comments

Comments
 (0)