Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app spec validate-offline (Resolves #1449) #1450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ Optionally, pass a deployment ID to get the spec of that specific deployment.`,
AddStringFlag(getCmd, doctl.ArgAppDeployment, "", "", "optional: a deployment ID")
AddStringFlag(getCmd, doctl.ArgFormat, "", "yaml", `the format to output the spec in; either "yaml" or "json"`)

validateCmd := CmdBuilder(cmd, RunAppsSpecValidate, "validate <spec file>", "Validate an application spec", `Use this command to check whether a given app spec (YAML or JSON) is valid.
validateCmd := cmdBuilderWithInit(cmd, RunAppsSpecValidate, "validate <spec file>", "Validate an application spec", `Use this command to check whether a given app spec (YAML or JSON) is valid.

You may pass - as the filename to read from stdin.`, Writer)
You may pass - as the filename to read from stdin.`, Writer, false)
AddBoolFlag(validateCmd, doctl.ArgSchemaOnly, "", false, "Only validate the spec schema and not the correctness of the spec.")

return cmd
Expand Down Expand Up @@ -762,6 +762,7 @@ func RunAppsSpecGet(c *CmdConfig) error {
}

// RunAppsSpecValidate validates an app spec file
// doesn't require auth & connection to the API with doctl.ArgSchemaOnly flag
func RunAppsSpecValidate(c *CmdConfig) error {
if len(c.Args) < 1 {
return doctl.NewMissingArgsErr(c.NS)
Expand All @@ -778,6 +779,7 @@ func RunAppsSpecValidate(c *CmdConfig) error {
return err
}

// validate schema only (offline)
if schemaOnly {
ymlSpec, err := yaml.Marshal(appSpec)
if err != nil {
Expand All @@ -787,6 +789,10 @@ func RunAppsSpecValidate(c *CmdConfig) error {
return err
}

// validate the spec against the API
if err := c.initServices(c); err != nil {
return err
}
res, err := c.Apps().Propose(&godo.AppProposeRequest{
Spec: appSpec,
})
Expand Down
18 changes: 18 additions & 0 deletions integration/apps_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ var _ = suite("apps/spec/validate", func(t *testing.T, when spec.G, it spec.S) {
expect.Equal(expectedOutput, strings.TrimSpace(string(output)))
})

it("schema-only works without auth", func() {
cmd := exec.Command(builtBinaryPath,
"-u", server.URL,
"apps", "spec", "validate",
"--schema-only", "-",
)
byt, err := json.Marshal(testAppSpec)
expect.NoError(err)

cmd.Stdin = bytes.NewReader(byt)

output, err := cmd.CombinedOutput()
expect.NoError(err)

expectedOutput := "name: test\nservices:\n- github:\n branch: main\n repo: digitalocean/doctl\n name: service"
expect.Equal(expectedOutput, strings.TrimSpace(string(output)))
})

it("calls proposeapp", func() {
cmd := exec.Command(builtBinaryPath,
"-t", "some-magic-token",
Expand Down