Skip to content

Commit 1031d97

Browse files
authored
Handle error from buildWorkflows() (#45)
* Print promise.configure in init promise.yaml - looks a little odd with just resource.configure * fix: return on failed to get workflow error
1 parent 3edd274 commit 1031d97

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

cmd/add_container.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ var addContainerCmd = &cobra.Command{
3535
Args: cobra.ExactArgs(1),
3636
}
3737

38-
var (
39-
image, containerName string
40-
container v1alpha1.Container
41-
)
38+
var image, containerName string
4239

4340
func init() {
4441
addCmd.AddCommand(addContainerCmd)

cmd/build_promise.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func BuildPromise(cmd *cobra.Command, args []string) error {
7777
}
7878

7979
var workflows v1alpha1.Workflows
80-
buildWorkflows(&workflows)
80+
if err := buildWorkflows(&workflows); err != nil {
81+
return err
82+
}
8183
promise.Spec.Workflows = workflows
8284

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

121123
promiseDelete, err := getWorkflow("promise", "delete")
122124
if err != nil {
123-
return err
125+
return fmt.Errorf("failed to get promise delete workflow: %v", err)
124126
}
125127

126128
resourceConfigure, err := getWorkflow("resource", "configure")
127129
if err != nil {
128-
return err
130+
return fmt.Errorf("failed to get resource configure workflow: %v", err)
129131
}
130132

131133
resourceDelete, err := getWorkflow("resource", "delete")
132134
if err != nil {
133-
return err
135+
return fmt.Errorf("failed to get resource delete workflow: %v", err)
134136
}
135137

136138
workflows.Promise.Configure = promiseConfigure

cmd/templates/promise/promise.yaml.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ spec:
2727
served: true
2828
storage: true
2929
workflows:
30+
promise:
31+
configure:
3032
resource:
3133
configure:
3234
{{ .ResourceConfigure | indent 8 }}

test/build_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ var _ = Describe("build", func() {
9898
Expect(err).NotTo(HaveOccurred())
9999
matchCRD(promiseCRD, "syntasso.io", "v1alpha1", "Database", "database", "databases")
100100
})
101+
102+
When("workflow file is invalid", func() {
103+
It("errors", func() {
104+
r.run("init", "promise", "postgresql", "--group", "syntasso.io", "--kind", "Database", "--split", "--dir", promiseDir)
105+
r.run("add", "container", "promise/configure/pipeline0", "--image", "psql:latest", "-n", "configure-image", "--dir", promiseDir)
106+
Expect(os.WriteFile(filepath.Join(promiseDir, "workflows/promise/configure/workflow.yaml"), []byte("not valid"), 0644)).To(Succeed())
107+
108+
r.exitCode = 1
109+
sess := r.run("build", "promise", "postgresql", "--dir", promiseDir)
110+
Expect(sess.Err).To(gbytes.Say("failed to get promise configure workflow:"))
111+
})
112+
})
101113
})
102114

103115
Context("dependencies.yaml file", func() {

0 commit comments

Comments
 (0)