Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kneeyo1 committed May 13, 2024
1 parent be902bf commit 45f1808
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/sentry/runner/commands/configoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ def sync(ctx: click.Context) -> None:
presenter_delegator.unset(opt.name)
else:
if (
options.can_update(opt.name, opt.value, options.UpdateChannel.AUTOMATOR)
options.can_update(
opt.name, options.get(opt.name), options.UpdateChannel.AUTOMATOR
)
== options.NotWritableReason.OPTION_ON_DISK
):
continue
Expand Down
2 changes: 2 additions & 0 deletions tests/sentry/runner/commands/badsync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
options:
set_on_disk_option: 'hello'
26 changes: 25 additions & 1 deletion tests/sentry/runner/commands/test_configoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
from pathlib import Path

import pytest
from django.conf import settings

from sentry import options
from sentry.options.manager import FLAG_AUTOMATOR_MODIFIABLE, FLAG_IMMUTABLE, UpdateChannel
from sentry.options.manager import (
FLAG_AUTOMATOR_MODIFIABLE,
FLAG_IMMUTABLE,
FLAG_PRIORITIZE_DISK,
UpdateChannel,
)
from sentry.runner.commands.configoptions import configoptions
from sentry.runner.commands.presenters.consolepresenter import ConsolePresenter
from sentry.testutils.cases import CliTestCase
Expand All @@ -24,6 +30,12 @@ def register_options(self) -> Generator[None, None, None]:
options.register("change_channel_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register("to_unset_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register("invalid_type", default=15, flags=FLAG_AUTOMATOR_MODIFIABLE)
options.register(
"set_on_disk_option",
default="",
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
)
settings.SENTRY_OPTIONS["set_on_disk_option"] = "test"

yield

Expand All @@ -36,6 +48,8 @@ def register_options(self) -> Generator[None, None, None]:
options.unregister("change_channel_option")
options.unregister("to_unset_option")
options.unregister("invalid_type")
options.unregister("set_on_disk_option")
del settings.SENTRY_OPTIONS["set_on_disk_option"]

@pytest.fixture(autouse=True)
def set_options(self) -> None:
Expand Down Expand Up @@ -184,6 +198,16 @@ def test_sync(self):

assert not options.isset("to_unset_option")

def test_bad_sync(self):
rv = self.invoke(
"-f",
"tests/sentry/runner/commands/badsync.yaml",
"sync",
)
assert rv.exit_code == 2, rv.output

assert ConsolePresenter.ERROR_MSG % ("set_on_disk_option", "option_on_disk") in rv.output

def test_bad_patch(self):
rv = self.invoke(
"--file=tests/sentry/runner/commands/badpatch.yaml",
Expand Down

0 comments on commit 45f1808

Please sign in to comment.