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

cmd/atlas/internal/cmdapi: review policy excludes auto-approve #2279

Merged
merged 1 commit into from
Nov 13, 2023
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
2 changes: 2 additions & 0 deletions cmd/atlas/internal/cmdapi/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func schemaApplyRun(cmd *cobra.Command, flags schemaApplyFlags, env *Env) error
return errors.New(`--log and --format can only be used with --dry-run or --auto-approve`)
case flags.txMode != txModeNone && flags.txMode != txModeFile:
return fmt.Errorf("unknown tx-mode %q", flags.txMode)
case flags.autoApprove && env.Lint.Review != "":
return fmt.Errorf("auto-approve is not allowed when a lint policy is set to %q", env.Lint.Review)
}
// If the old -f flag is given convert them to the URL format. If both are given,
// cobra would throw an error since they are marked as mutually exclusive.
Expand Down
27 changes: 27 additions & 0 deletions cmd/atlas/internal/cmdapi/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,33 @@ table "bad" {
})
}

func TestSchema_ApplyReview(t *testing.T) {
t.Run("mutex-auto-approve", func(t *testing.T) {
cfg := filepath.Join(t.TempDir(), "atlas.hcl")
require.NoError(t, os.WriteFile(cfg, []byte(`env "test" {
lint {
review = WARNING
}
}`), 0600))
db := openSQLite(t, "")
p := filepath.Join(t.TempDir(), "schema.sql")
require.NoError(t, os.WriteFile(p, []byte(`create table t1 (id int NOT NULL);`), 0600))
cmd := schemaCmd()
cmd.AddCommand(schemaApplyCmd())
_, err := runCmd(
cmd,
"apply",
"-c", "file://"+cfg,
"--url", db,
"--env", "test",
"--dev-url", openSQLite(t, ""),
"--to", "file://"+p,
"--auto-approve",
)
require.ErrorContains(t, err, `auto-approve is not allowed when a lint policy is set to "WARNING"`)
})
}

func TestSchema_InspectLog(t *testing.T) {
db := openSQLite(t, "create table t1 (id integer primary key);create table t2 (name text);")
cmd := schemaCmd()
Expand Down