-
Notifications
You must be signed in to change notification settings - Fork 279
/
config_test.rb
120 lines (95 loc) · 3.08 KB
/
config_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require "test_helper"
class ConfigTest < Rugged::TestCase
def setup
@repo = FixtureRepo.from_rugged("testrepo.git")
path = Dir.mktmpdir("rugged-global-config")
cfg = Rugged::Config.new(File.join(path, ".gitconfig"))
cfg['user.name'] = "The test suite"
Rugged::Settings['search_path_global'] = path
@glocalconfigdir = path
end
def cleanup
FileUtils.remove_entry_secure(@globalconfigdir)
end
def test_multi_fetch
config = @repo.config
fetches = ["+refs/heads/*:refs/remotes/test_remote/*",
"+refs/heads/*:refs/remotes/hello_remote/*"]
assert_equal fetches, config.get_all("remote.test_multiple_fetches.fetch")
end
def test_read_config_file
config = @repo.config
assert_equal 'false', config['core.bare']
assert_nil config['not.exist']
end
def test_read_config_from_path
config = Rugged::Config.new(File.join(@repo.path, 'config'))
assert_equal 'false', config['core.bare']
end
def test_read_global_config_file
config = Rugged::Config.global
refute_nil config['user.name']
assert_nil config['core.bare']
end
def test_snapshot
config = Rugged::Config.new(File.join(@repo.path, 'config'))
config['old.value'] = 5
snapshot = config.snapshot
assert_equal '5', snapshot['old.value']
config['new.value'] = 42
config['old.value'] = 1337
assert_equal '5', snapshot['old.value']
assert_nil snapshot['new.value']
end
def test_each_key_is_a_string
config = @repo.config
config.each_key do |key|
assert key.is_a?(String)
end
end
def test_each_pair_is_pairs
config = @repo.config
config.each_pair do |key, value|
assert key.is_a?(String)
assert value.is_a?(String)
end
end
def test_transaction
config = Rugged::Config.new(File.join(@repo.path, 'config'))
config['section.name'] = 'value'
config2 = Rugged::Config.new(File.join(@repo.path, 'config'))
config.transaction do
config['section.name'] = 'other value'
config['section2.name3'] = 'more value'
assert_equal 'value', config2['section.name']
assert_nil config2['section2.name3']
assert_equal 'value', config['section.name']
assert_nil config['section2.name3']
end
assert_equal 'other value', config['section.name']
assert_equal 'more value', config['section2.name3']
assert_equal 'other value', config2['section.name']
assert_equal 'more value', config2['section2.name3']
end
end
class ConfigWriteTest < Rugged::TestCase
def setup
@source_repo = FixtureRepo.from_rugged("testrepo.git")
@repo = FixtureRepo.clone(@source_repo)
@path = @repo.workdir
end
def test_write_config_values
config = @repo.config
config['custom.value'] = 'my value'
config2 = @repo.config
assert_equal 'my value', config2['custom.value']
content = File.read(File.join(@repo.path, 'config'))
assert_match(/value = my value/, content)
end
def test_delete_config_values
config = @repo.config
config.delete('core.bare')
config2 = @repo.config
assert_nil config2.get('core.bare')
end
end