cc-os/plugins/os-backlog/tests/config_test.rb

69 lines
2.1 KiB
Ruby
Raw Normal View History

require_relative "test_helper"
class ConfigTest < Minitest::Test
def test_nil_contents_is_unconfigured
config = Backlog::Config.new(nil)
refute config.configured?
assert_nil config.board
end
def test_blank_contents_is_unconfigured
config = Backlog::Config.new(" \n")
refute config.configured?
end
def test_reads_board_key
config = Backlog::Config.new("board=llf-schema\n")
assert config.configured?
assert_equal "llf-schema", config.board
end
def test_reads_legacy_yaml_style_board_key
config = Backlog::Config.new("---\nboard: llf-schema\n")
assert config.configured?
assert_equal "llf-schema", config.board
end
def test_lines_without_separator_are_ignored
config = Backlog::Config.new("# comment\njunk line\n")
refute config.configured?
end
def test_contents_without_board_key_is_unconfigured
config = Backlog::Config.new("other=value\n")
refute config.configured?
end
def test_reads_tracker_key
config = Backlog::Config.new("tracker=forgejo:jared/cc-os\n")
assert config.tracker_configured?
assert_equal "forgejo:jared/cc-os", config.tracker
end
def test_tracker_unconfigured_when_absent
config = Backlog::Config.new("board=llf-schema\n")
refute config.tracker_configured?
end
def test_merge_sets_new_key_on_nil_contents
contents = Backlog::Config.merge(nil, "tracker", "forgejo:jared/cc-os")
assert_equal "tracker=forgejo:jared/cc-os\n", contents
end
def test_merge_preserves_other_keys
existing = "board=llf-schema\nother=kept\n"
updated_contents = Backlog::Config.merge(existing, "tracker", "planka:llf-schema")
updated = Backlog::Config.new(updated_contents)
assert_equal "llf-schema", updated.board
assert_equal "planka:llf-schema", updated.tracker
assert_equal "kept", updated.to_h["other"]
end
def test_merge_overwrites_existing_value_for_key
existing = "tracker=repo:old\n"
updated = Backlog::Config.new(Backlog::Config.merge(existing, "tracker", "repo:new"))
assert_equal "repo:new", updated.tracker
end
end