-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
217 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/pivotal-cf/jhanda" | ||
|
||
"github.com/pivotal-cf/kiln/pkg/bake" | ||
"github.com/pivotal-cf/kiln/pkg/cargo" | ||
) | ||
|
||
type New struct { | ||
Options struct { | ||
Dir string `long:"directory" description:"path to directory where source should be written" default:"."` | ||
Tile string `long:"tile" description:"tile path" required:"true"` | ||
Slug string `long:"product-slug" description:"a TanzuNet product slug"` | ||
KilnfileTemplate string `long:"kilnfile-template" description:"a Kilnfile template sets up some reasonable Kilnfile defaults one of [artifactory, bosh.io]" default:"bosh.io"` | ||
} | ||
} | ||
|
||
func (n *New) Execute(args []string) error { | ||
k, err := n.Setup(args) | ||
if err != nil { | ||
return err | ||
} | ||
k.Slug = n.Options.Slug | ||
return bake.New(n.Options.Dir, n.Options.Tile, k) | ||
} | ||
|
||
func (n *New) Setup(args []string) (cargo.Kilnfile, error) { | ||
if _, err := jhanda.Parse(&n.Options, args); err != nil { | ||
return cargo.Kilnfile{}, err | ||
} | ||
k, err := cargo.KilnfileTemplate(n.Options.KilnfileTemplate) | ||
if err != nil { | ||
return cargo.Kilnfile{}, err | ||
} | ||
return k, nil | ||
} | ||
|
||
func (n *New) Usage() jhanda.Usage { | ||
return jhanda.Usage{ | ||
Description: "generate tile source from a tile", | ||
ShortDescription: "generate source", | ||
Flags: n.Options, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/pivotal-cf/kiln/pkg/bake" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/pivotal-cf/kiln/pkg/cargo" | ||
) | ||
|
||
var _ = FDescribe("new", func() { | ||
var ( | ||
directory string | ||
n *New | ||
|
||
args []string | ||
) | ||
|
||
BeforeEach(func() { | ||
var err error | ||
directory, err = os.MkdirTemp("", "kiln-new-*") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
n = new(New) | ||
}) | ||
|
||
When("the tile flag is not set", func() { | ||
It("returns an error", func() { | ||
_, err := n.Setup(nil) | ||
Expect(err).To(MatchError(ContainSubstring("--tile"))) | ||
}) | ||
}) | ||
|
||
When("only required arguments are set", func() { | ||
BeforeEach(func() { | ||
args = []string{ | ||
"--tile", filepath.FromSlash("testdata/tile-0.1.2.pivotal"), | ||
} | ||
}) | ||
It("does not error out", func() { | ||
_, err := n.Setup(args) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
It("sets some release sources", func() { | ||
k, _ := n.Setup(args) | ||
Expect(k.ReleaseSources).NotTo(BeEmpty()) | ||
}) | ||
It("sets the current working directory", func() { | ||
_, _ = n.Setup(args) | ||
Expect(n.Options.Dir).To(Equal(".")) | ||
}) | ||
It("does not set the product slug", func() { | ||
_, _ = n.Setup(args) | ||
Expect(n.Options.Slug).To(BeEmpty()) | ||
}) | ||
It("sset the bosh.io release source kilnfile template", func() { | ||
_, _ = n.Setup(args) | ||
Expect(n.Options.KilnfileTemplate).To(Equal(cargo.BOSHReleaseTarballSourceTypeBOSHIO)) | ||
}) | ||
}) | ||
|
||
When("generating source", func() { | ||
BeforeEach(func() { | ||
args = []string{ | ||
"--tile", filepath.FromSlash("testdata/tile-0.1.3.pivotal"), | ||
"--directory", directory, | ||
} | ||
}) | ||
It("generates tile source", func() { | ||
Expect(n.Execute(args)).To(Succeed()) | ||
|
||
Expect(filepath.Join(directory, bake.DefaultFilepathKilnfile)).To(BeAnExistingFile()) | ||
Expect(filepath.Join(directory, bake.DefaultFilepathKilnfileLock)).To(BeAnExistingFile()) | ||
Expect(filepath.Join(directory, bake.DefaultFilepathBaseYML)).To(BeAnExistingFile()) | ||
Expect(filepath.Join(directory, bake.DefaultFilepathIconImage)).To(BeAnExistingFile()) | ||
}) | ||
}) | ||
}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters