Skip to content

Commit

Permalink
Handle error from buildWorkflows() (#45)
Browse files Browse the repository at this point in the history
* Print promise.configure in init promise.yaml

- looks a little odd with just resource.configure

* fix: return on failed to get workflow error
  • Loading branch information
ChunyiLyu authored Jul 29, 2024
1 parent 3edd274 commit 1031d97
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 1 addition & 4 deletions cmd/add_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ var addContainerCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
}

var (
image, containerName string
container v1alpha1.Container
)
var image, containerName string

func init() {
addCmd.AddCommand(addContainerCmd)
Expand Down
12 changes: 7 additions & 5 deletions cmd/build_promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func BuildPromise(cmd *cobra.Command, args []string) error {
}

var workflows v1alpha1.Workflows
buildWorkflows(&workflows)
if err := buildWorkflows(&workflows); err != nil {
return err
}
promise.Spec.Workflows = workflows

promiseBytes, err := yaml.Marshal(promise)
Expand Down Expand Up @@ -115,22 +117,22 @@ func fileExists(filePath string) bool {
func buildWorkflows(workflows *v1alpha1.Workflows) error {
promiseConfigure, err := getWorkflow("promise", "configure")
if err != nil {
return err
return fmt.Errorf("failed to get promise configure workflow: %v", err)
}

promiseDelete, err := getWorkflow("promise", "delete")
if err != nil {
return err
return fmt.Errorf("failed to get promise delete workflow: %v", err)
}

resourceConfigure, err := getWorkflow("resource", "configure")
if err != nil {
return err
return fmt.Errorf("failed to get resource configure workflow: %v", err)
}

resourceDelete, err := getWorkflow("resource", "delete")
if err != nil {
return err
return fmt.Errorf("failed to get resource delete workflow: %v", err)
}

workflows.Promise.Configure = promiseConfigure
Expand Down
2 changes: 2 additions & 0 deletions cmd/templates/promise/promise.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
served: true
storage: true
workflows:
promise:
configure:
resource:
configure:
{{ .ResourceConfigure | indent 8 }}
12 changes: 12 additions & 0 deletions test/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ var _ = Describe("build", func() {
Expect(err).NotTo(HaveOccurred())
matchCRD(promiseCRD, "syntasso.io", "v1alpha1", "Database", "database", "databases")
})

When("workflow file is invalid", func() {
It("errors", func() {
r.run("init", "promise", "postgresql", "--group", "syntasso.io", "--kind", "Database", "--split", "--dir", promiseDir)
r.run("add", "container", "promise/configure/pipeline0", "--image", "psql:latest", "-n", "configure-image", "--dir", promiseDir)
Expect(os.WriteFile(filepath.Join(promiseDir, "workflows/promise/configure/workflow.yaml"), []byte("not valid"), 0644)).To(Succeed())

r.exitCode = 1
sess := r.run("build", "promise", "postgresql", "--dir", promiseDir)
Expect(sess.Err).To(gbytes.Say("failed to get promise configure workflow:"))
})
})
})

Context("dependencies.yaml file", func() {
Expand Down

0 comments on commit 1031d97

Please sign in to comment.