-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathconfig_test.rb
More file actions
111 lines (87 loc) · 3.03 KB
/
config_test.rb
File metadata and controls
111 lines (87 loc) · 3.03 KB
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
require "test_helper"
class ConfigTest < Rugged::TestCase
def setup
@repo = FixtureRepo.from_rugged("testrepo.git")
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_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_write_multivar_config_values
config = @repo.config
config.add('custom.multivalue', 'my value')
config.add('custom.multivalue', true)
config.add('custom.multivalue', 42)
config2 = @repo.config
custom_multivar = ['my value', 'true', '42']
assert_equal custom_multivar, config2.get_all('custom.multivalue')
content = File.read(File.join(@repo.path, 'config'))
assert_match(/multivalue = my value/, content)
assert_match(/multivalue = true/, content)
assert_match(/multivalue = 42/, 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