Skip to content

Commit

Permalink
gen mtad fixed to generate mtad.yaml in the source or target (if prov…
Browse files Browse the repository at this point in the history
…ided) folder
  • Loading branch information
allaVolkov committed Feb 19, 2019
1 parent 93a44c4 commit cf5c86c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
validateCmd.Flags().StringVarP(&validateCmdDesc, "desc", "d", "",
"the MTA descriptor; supported values: dev (development descriptor, default value) and dep (deployment descriptor)")
validateCmd.Flags().StringVarP(&validateCmdStrict, "strict", "r", "",
"the strictness indicator; supported values: true (strict, default value) and false (not strict)")
"if set to true duplicated fields and fields not defined in the mta yaml schema will be reported as errors, otherwise as warnings")
}

// generateCmd - Parent of all generation commands
Expand Down
5 changes: 1 addition & 4 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
// mtad command flags
var mtadCmdSrc string
var mtadCmdTrg string
var mtadCmdDesc string
var mtadCmdPlatform string

// meta command flags
Expand All @@ -33,8 +32,6 @@ func init() {
"the path to the MTA project; the current path is default")
mtadCmd.Flags().StringVarP(&mtadCmdTrg, "target", "t",
"", "the path to the MBT results folder; the current path is default")
mtadCmd.Flags().StringVarP(&mtadCmdDesc, "desc", "d", "",
"the MTA descriptor; supported values: dev (development descriptor, default value) and dep (deployment descriptor)")
mtadCmd.Flags().StringVarP(&mtadCmdPlatform, "platform", "p", "", "Provide MTA platform ")

// set flags of meta command
Expand Down Expand Up @@ -63,7 +60,7 @@ var mtadCmd = &cobra.Command{
Long: "generates deployment descriptor (mtad.yaml) from development descriptor (mta.yaml)",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
err := artifacts.ExecuteGenMtad(mtadCmdSrc, mtadCmdTrg, mtadCmdDesc, mtadCmdPlatform, os.Getwd)
err := artifacts.ExecuteGenMtad(mtadCmdSrc, mtadCmdTrg, mtadCmdPlatform, os.Getwd)
logError(err)
return err
},
Expand Down
9 changes: 2 additions & 7 deletions cmd/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/SAP/cloud-mta-build-tool/internal/fs"
"github.com/SAP/cloud-mta-build-tool/internal/platform"
"path/filepath"
)

var _ = Describe("Commands", func() {
Expand All @@ -32,7 +33,6 @@ var _ = Describe("Commands", func() {
var ep dir.Loc

AfterEach(func() {
mtadCmdDesc = ""
os.RemoveAll(getTestPath("result"))
})

Expand All @@ -48,12 +48,7 @@ var _ = Describe("Commands", func() {
mtadCmdSrc = getTestPath("mtahtml5")
mtadCmdPlatform = "cf"
Ω(mtadCmd.RunE(nil, []string{})).Should(Succeed())
Ω(ep.GetMtadPath()).Should(BeAnExistingFile())
})
It("Generate Mtad - Invalid deployment descriptor", func() {
mtadCmdSrc = getTestPath("mtahtml5")
mtadCmdDesc = "xx"
Ω(mtadCmd.RunE(nil, []string{})).Should(HaveOccurred())
Ω(filepath.Join(getTestPath("result"), "mtad.yaml")).Should(BeAnExistingFile())
})
It("Generate Mtad - Invalid source", func() {
mtadCmdSrc = getTestPath("mtahtml6")
Expand Down
28 changes: 21 additions & 7 deletions internal/artifacts/mtad.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@ import (
"github.com/SAP/cloud-mta-build-tool/internal/logs"

"github.com/SAP/cloud-mta/mta"
"path/filepath"
)


type mtadLoc struct{
path string
}

func (loc *mtadLoc) GetMtadPath() string {
return filepath.Join(loc.path, dir.Mtad)
}

func (loc *mtadLoc) GetMetaPath() string {
return loc.path
}

func (loc *mtadLoc) GetManifestPath() string {
return ""
}

// ExecuteGenMtad - generates MTAD from MTA
func ExecuteGenMtad(source, target, desc, platform string, wdGetter func() (string, error)) error {
func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, error)) error {
logs.Logger.Info("generating the MTAD file...")
loc, err := dir.Location(source, target, desc, wdGetter)
loc, err := dir.Location(source, target, dir.Dev, wdGetter)
if err != nil {
return errors.Wrap(err, "generation of the MTAD file failed when initializing the location")
}
Expand All @@ -35,11 +53,7 @@ func ExecuteGenMtad(source, target, desc, platform string, wdGetter func() (stri
mta.Merge(mtaStr, mtaExt)
adaptMtadForDeployment(mtaStr, platform)

err = genMtad(mtaStr, loc, loc.IsDeploymentDescriptor(), platform, yaml.Marshal)
if err != nil {
return err
}
return nil
return genMtad(mtaStr, &mtadLoc{target}, false, platform, yaml.Marshal)
}

// genMtad generates an mtad.yaml file from a mta.yaml file and a platform configuration file.
Expand Down
12 changes: 6 additions & 6 deletions internal/artifacts/mtad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ var _ = Describe("Mtad", func() {

var _ = Describe("ExecuteGenMtad", func() {
It("Sanity", func() {
Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "dev", "cf", os.Getwd)).Should(Succeed())
Ω(getTestPath("resultMtad", "mta_mta_build_tmp", "META-INF", "mtad.yaml")).Should(BeAnExistingFile())
Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(Succeed())
Ω(getTestPath("resultMtad", "mtad.yaml")).Should(BeAnExistingFile())
})
It("Fails on location initialization", func() {
Ω(ExecuteGenMtad("", getTestPath("resultMtad"), "dev", "cf", func() (string, error) {
Ω(ExecuteGenMtad("", getTestPath("resultMtad"), "cf", func() (string, error) {
return "", errors.New("err")
})).Should(HaveOccurred())
})
It("Fails on wrong source path - parse fails", func() {
Ω(ExecuteGenMtad(getTestPath("mtax"), getTestPath("resultMtad"), "dev", "cf", os.Getwd)).Should(HaveOccurred())
Ω(ExecuteGenMtad(getTestPath("mtax"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(HaveOccurred())
})
It("Fails on broken extension file - parse ext fails", func() {
Ω(ExecuteGenMtad(getTestPath("mtaWithBrokenExt"), getTestPath("resultMtad"), "dev", "cf", os.Getwd)).Should(HaveOccurred())
Ω(ExecuteGenMtad(getTestPath("mtaWithBrokenExt"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(HaveOccurred())
})
It("Fails on broken platforms configuration", func() {
cfg := platform.PlatformConfig
platform.PlatformConfig = []byte("abc abc")
Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "dev", "cf", os.Getwd)).Should(HaveOccurred())
Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(HaveOccurred())
platform.PlatformConfig = cfg
})
})
Expand Down
7 changes: 4 additions & 3 deletions internal/fs/mta_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const (
Dev = "dev"
// TempFolderSuffix - temporary folder suffix
TempFolderSuffix = "_mta_build_tmp"
mtad = "mtad.yaml"
// Mtad - deployment descriptor file name
Mtad = "mtad.yaml"
)

// IMtaParser - MTA Parser interface
Expand Down Expand Up @@ -140,7 +141,7 @@ func (ep *Loc) GetSourceModuleDir(modulePath string) string {
func (ep *Loc) GetMtaYamlFilename() string {
if ep.MtaFilename == "" {
if ep.Descriptor == Dep {
return mtad
return Mtad
}
return "mta.yaml"
}
Expand All @@ -164,7 +165,7 @@ func (ep *Loc) GetMetaPath() string {

// GetMtadPath gets the path to the generated MTAD file.
func (ep *Loc) GetMtadPath() string {
return filepath.Join(ep.GetMetaPath(), mtad)
return filepath.Join(ep.GetMetaPath(), Mtad)
}

// GetManifestPath gets the path to the generated manifest file.
Expand Down

0 comments on commit cf5c86c

Please sign in to comment.