conflict 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +174 -0
- data/README +23 -0
- data/Rakefile +63 -0
- data/bin/conflict +13 -0
- data/lib/conflict.rb +27 -0
- data/lib/conflict/core.rb +170 -0
- data/lib/conflict/domain.rb +89 -0
- data/lib/conflict/parsers.rb +130 -0
- data/lib/run_conflict +26 -0
- data/test/common.rb +132 -0
- data/test/data/a13g.diff.txt +379 -0
- data/test/data/apache_myfaces.diff.txt +22 -0
- data/test/data/rails.diff.txt +13 -0
- data/test/data/rails.info.txt +11 -0
- data/test/data/stomp/stomp.1.diff.txt +21 -0
- data/test/data/stomp/stomp.1.info.txt +11 -0
- data/test/data/stomp/stomp.2.diff.txt +21 -0
- data/test/data/stomp/stomp.2.info.txt +11 -0
- data/test/data/three/added.diff.txt +11 -0
- data/test/data/three/changed.diff.txt +12 -0
- data/test/data/three/conflict.info.txt +11 -0
- data/test/data/three/deleted.diff.txt +11 -0
- data/test/database_test.rb +130 -0
- data/test/equality_test.rb +60 -0
- data/test/event_test.rb +40 -0
- data/test/negative_test.rb +107 -0
- data/test/parser_test.rb +98 -0
- data/test/round_trip/expiration_test.rb +56 -0
- data/test/round_trip/happy_path_test.rb +105 -0
- data/test/round_trip/multi_diff_test.rb +67 -0
- data/test/round_trip/multiple_actions_test.rb +82 -0
- data/test/round_trip/negative_test.rb +79 -0
- data/test/round_trip/relative_path_test.rb +63 -0
- metadata +86 -0
data/test/parser_test.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
require File.dirname(__FILE__) + '/common.rb'
|
22
|
+
|
23
|
+
class ParserTest < Test::Unit::TestCase
|
24
|
+
include ConflictConstants
|
25
|
+
COMMON_PROPERTIES = {:path=>".", :ttl=>Conflict::TTL}
|
26
|
+
|
27
|
+
def test_info_parser
|
28
|
+
|
29
|
+
parser = InfoParser::new
|
30
|
+
info = File.new(STOMP_1_INFO_PATH).to_s
|
31
|
+
properties = parser.parse info
|
32
|
+
assert_equal STOMP_1_URL, properties[:url]
|
33
|
+
|
34
|
+
info = File.new(STOMP_2_INFO_PATH).to_s
|
35
|
+
properties = parser.parse info
|
36
|
+
assert_equal STOMP_2_URL, properties[:url]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_diff_parser_with_info
|
40
|
+
|
41
|
+
diff = File::new(STOMP_1_DIFF_PATH).to_s
|
42
|
+
parser = DiffParser::new({:url=>STOMP_1_URL}.merge(COMMON_PROPERTIES))
|
43
|
+
events = parser.parse diff, CLIENT_ONE
|
44
|
+
|
45
|
+
assert_equal 1, events.size
|
46
|
+
first_event = events[0]
|
47
|
+
|
48
|
+
diff = File::new(STOMP_2_DIFF_PATH).to_s
|
49
|
+
parser = DiffParser::new({:url=>STOMP_2_URL}.merge(COMMON_PROPERTIES))
|
50
|
+
events = parser.parse diff, CLIENT_ONE
|
51
|
+
|
52
|
+
assert_equal 1, events.size
|
53
|
+
second_event = events[0]
|
54
|
+
assert first_event.eql?(second_event)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_diff_parser_two_changes_same_file
|
58
|
+
|
59
|
+
url = 'https://svn.apache.org/repos/asf/myfaces/core/trunk/api/src/main/java/javax'
|
60
|
+
parser = DiffParser::new({:url=>url}.merge(COMMON_PROPERTIES))
|
61
|
+
diff = File.new(DATA_DIR + 'apache_myfaces.diff.txt').to_s
|
62
|
+
events = parser.parse diff, CLIENT_ONE
|
63
|
+
|
64
|
+
assert_equal 1, events.size
|
65
|
+
assert events[0].eql?(Event::new(CLIENT_ONE, "changed", url + "/FacesServlet.java"))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_diff_parser_deleted_added_changed_in_same_patch
|
69
|
+
|
70
|
+
url = 'http://activemessaging.googlecode.com/svn/trunk/plugins/activemessaging/lib'
|
71
|
+
parser = DiffParser::new({:url=>url}.merge(COMMON_PROPERTIES))
|
72
|
+
diff = File.new(DATA_DIR + 'a13g.diff.txt').to_s
|
73
|
+
events = parser.parse diff, CLIENT_ONE
|
74
|
+
|
75
|
+
assert_equal 3, events.size
|
76
|
+
assert events[0].eql?(Event::new(CLIENT_ONE, "deleted", url + "/asqs.rb"))
|
77
|
+
assert events[1].eql?(Event::new(CLIENT_ONE, "changed", url + "/jms.rb"))
|
78
|
+
assert events[2].eql?(Event::new(CLIENT_ONE, "added", url + "/new.rb"))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_diff_parser_deleted_added_changed_in_different_files
|
82
|
+
|
83
|
+
resource = CONFLICT_URL + '/test_data.txt'
|
84
|
+
parser = DiffParser::new({:url=>CONFLICT_URL}.merge(COMMON_PROPERTIES))
|
85
|
+
added = File::new(DATA_DIR + "three/added.diff.txt").to_s
|
86
|
+
deleted = File::new(DATA_DIR + "three/deleted.diff.txt").to_s
|
87
|
+
changed = File::new(DATA_DIR + "three/changed.diff.txt").to_s
|
88
|
+
|
89
|
+
events = parser.parse added, CLIENT_ONE
|
90
|
+
assert events[0].eql?(Event::new(CLIENT_ONE, "added", resource))
|
91
|
+
|
92
|
+
events = parser.parse deleted, CLIENT_ONE
|
93
|
+
assert events[0].eql?(Event::new(CLIENT_ONE, "deleted", resource))
|
94
|
+
|
95
|
+
events = parser.parse changed, CLIENT_ONE
|
96
|
+
assert events[0].eql?(Event::new(CLIENT_ONE, "changed", resource))
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripExpirationTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
|
25
|
+
def test_expiration
|
26
|
+
|
27
|
+
diff = File.new("./test/data/rails.diff.txt").to_s
|
28
|
+
info = File.new("./test/data/rails.info.txt").to_s
|
29
|
+
ttl = 0
|
30
|
+
|
31
|
+
cfg = {:port=>86}
|
32
|
+
thread = Thread.new do
|
33
|
+
Server::new(cfg.merge({:ttl=>ttl})).start
|
34
|
+
end
|
35
|
+
|
36
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(cfg))
|
37
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(cfg))
|
38
|
+
|
39
|
+
conflicts = client_one.diff diff, info
|
40
|
+
assert_equal 0, conflicts.size
|
41
|
+
assert_equal 1, client_one.count
|
42
|
+
|
43
|
+
sleep(ttl + 1) # let it expire
|
44
|
+
|
45
|
+
assert_equal 1, client_one.count, "server will not dump the event until next request"
|
46
|
+
|
47
|
+
conflicts = client_two.diff diff, info
|
48
|
+
assert_equal 0, conflicts.size, "should not conflict w/ expired event"
|
49
|
+
assert_equal 1, client_one.count, "expired event should be gone"
|
50
|
+
|
51
|
+
thread.kill
|
52
|
+
thread.join(5)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
RESOURCE = "http://svn.rubyonrails.org/rails/trunk/release.rb"
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@diff = File.new("./test/data/rails.diff.txt").to_s
|
28
|
+
@info = File.new("./test/data/rails.info.txt").to_s
|
29
|
+
|
30
|
+
@first = Event::new(CLIENT_ONE, "changed", RESOURCE)
|
31
|
+
@second = Event::new(CLIENT_TWO, "changed", RESOURCE)
|
32
|
+
@third = Event::new(CLIENT_THREE, "changed", RESOURCE)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_happy_path_conflict_accumalation
|
37
|
+
happy_path_conflict_accumalation nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_happy_path_conflict_accumalation_with_alternate_port_and_url
|
41
|
+
happy_path_conflict_accumalation 81
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def happy_path_conflict_accumalation port
|
46
|
+
|
47
|
+
cfg = {:port=>port}
|
48
|
+
@thread = Thread.new do
|
49
|
+
Server::new(cfg).start
|
50
|
+
end
|
51
|
+
|
52
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(cfg))
|
53
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(cfg))
|
54
|
+
client_three = Client::new({:id=>CLIENT_THREE}.merge(cfg))
|
55
|
+
|
56
|
+
response = client_one.diff @diff, @info
|
57
|
+
assert [].eql?(response)
|
58
|
+
assert_equal 1, client_one.count
|
59
|
+
|
60
|
+
response = client_two.diff(@diff, @info)
|
61
|
+
assert [Conflict::Conflict.new(@second, @first)].eql?(response)
|
62
|
+
assert_equal 2, client_one.count
|
63
|
+
|
64
|
+
response = client_three.diff @diff, @info
|
65
|
+
assert [Conflict::Conflict.new(@third, @first), Conflict::Conflict::new(@third, @second)].eql?(response)
|
66
|
+
assert_equal 3, client_one.count
|
67
|
+
|
68
|
+
response = client_one.resend
|
69
|
+
assert [Conflict::Conflict.new(@first, @second), Conflict::Conflict::new(@first, @third)].eql?(response)
|
70
|
+
assert_equal 3, client_one.count
|
71
|
+
|
72
|
+
response = client_two.resend
|
73
|
+
assert [Conflict::Conflict.new(@second, @third), Conflict::Conflict::new(@second, @first)].eql?(response)
|
74
|
+
assert_equal 3, client_one.count
|
75
|
+
|
76
|
+
response = client_three.revert @info
|
77
|
+
assert [].eql?(response)
|
78
|
+
assert_equal 2, client_one.count
|
79
|
+
|
80
|
+
response = client_two.resend
|
81
|
+
assert [Conflict::Conflict.new(@second, @first)].eql?(response)
|
82
|
+
assert_equal 2, client_one.count
|
83
|
+
|
84
|
+
response = client_one.resend
|
85
|
+
assert [Conflict::Conflict.new(@first, @second)].eql?(response)
|
86
|
+
assert_equal 2, client_one.count
|
87
|
+
|
88
|
+
response = client_two.revert @info
|
89
|
+
assert [].eql?(response)
|
90
|
+
assert_equal 1, client_one.count
|
91
|
+
|
92
|
+
response = client_one.resend
|
93
|
+
assert [].eql?(response)
|
94
|
+
assert_equal 1, client_one.count
|
95
|
+
|
96
|
+
response = client_one.revert @info
|
97
|
+
assert [].eql?(response)
|
98
|
+
assert_equal 0, client_one.count
|
99
|
+
|
100
|
+
@thread.kill
|
101
|
+
@thread.join(5)
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripMultiDiffTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
|
25
|
+
def test_dev_with_no_conflicts
|
26
|
+
|
27
|
+
@cfg = {:port=>85}
|
28
|
+
@thread = Thread.new do
|
29
|
+
Server::new(@cfg).start
|
30
|
+
end
|
31
|
+
|
32
|
+
rails_diff = File.new("./test/data/rails.diff.txt").to_s
|
33
|
+
rails_info = File.new("./test/data/rails.info.txt").to_s
|
34
|
+
stomp_one_diff = File::new(STOMP_1_DIFF_PATH).to_s
|
35
|
+
stomp_one_info = File.new(STOMP_1_INFO_PATH).to_s
|
36
|
+
stomp_two_diff = File::new(STOMP_2_DIFF_PATH).to_s
|
37
|
+
stomp_two_info = File.new(STOMP_2_INFO_PATH).to_s
|
38
|
+
|
39
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(@cfg))
|
40
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(@cfg))
|
41
|
+
client_three = Client::new({:id=>CLIENT_THREE}.merge(@cfg))
|
42
|
+
|
43
|
+
response = client_one.multi_diff [rails_diff, stomp_one_diff], [rails_info, stomp_one_info]
|
44
|
+
assert_equal [], response
|
45
|
+
|
46
|
+
response = client_one.multi_diff [stomp_two_diff], [stomp_two_info]
|
47
|
+
assert_equal [], response
|
48
|
+
|
49
|
+
response = client_one.multi_diff [stomp_one_diff], [stomp_one_info]
|
50
|
+
assert_equal [], response
|
51
|
+
|
52
|
+
response = client_three.multi_diff [rails_diff], [rails_info]
|
53
|
+
assert_equal [], response
|
54
|
+
|
55
|
+
client_one.revert rails_info
|
56
|
+
client_two.revert rails_info
|
57
|
+
client_three.revert rails_info
|
58
|
+
@thread.kill
|
59
|
+
@thread.join(5)
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_dev_with_conflicts
|
64
|
+
# this needs to get done
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripMultipleActionsTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
RESOURCE = CONFLICT_URL + '/test_data.txt'
|
25
|
+
DATA_DIR = './test/data/three/'
|
26
|
+
|
27
|
+
def setup
|
28
|
+
|
29
|
+
@added = File::new(DATA_DIR + "added.diff.txt").to_s
|
30
|
+
@deleted = File::new(DATA_DIR + "deleted.diff.txt").to_s
|
31
|
+
@changed = File::new(DATA_DIR + "changed.diff.txt").to_s
|
32
|
+
@info = File::new(DATA_DIR + "conflict.info.txt").to_s
|
33
|
+
|
34
|
+
@first = Event::new(CLIENT_ONE, "added", RESOURCE)
|
35
|
+
@second = Event::new(CLIENT_TWO, "deleted", RESOURCE)
|
36
|
+
@third = Event::new(CLIENT_THREE, "changed", RESOURCE)
|
37
|
+
|
38
|
+
@conf = {:port=>83}
|
39
|
+
|
40
|
+
@thread = Thread.new do
|
41
|
+
Server::new(@conf).start
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
@thread.kill
|
48
|
+
@thread.join(5)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_workflow_using_add_delete_and_change
|
52
|
+
|
53
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(@conf)) # dev start conflict clients
|
54
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(@conf))
|
55
|
+
client_three = Client::new({:id=>CLIENT_THREE}.merge(@conf))
|
56
|
+
|
57
|
+
response = client_one.diff(@added, @info)
|
58
|
+
assert_equal [], response
|
59
|
+
|
60
|
+
response = client_two.diff(@deleted, @info)
|
61
|
+
assert [Conflict::Conflict.new(@second, @first)].eql?(response)
|
62
|
+
|
63
|
+
response = client_three.diff(@changed, @info)
|
64
|
+
assert [Conflict::Conflict.new(@third, @first),Conflict::Conflict.new(@third, @second)].eql?(response)
|
65
|
+
|
66
|
+
response = client_two.revert @info
|
67
|
+
assert_equal [], response
|
68
|
+
|
69
|
+
response = client_one.diff(@added, @info)
|
70
|
+
assert [Conflict::Conflict.new(@first, @third)].eql?(response)
|
71
|
+
|
72
|
+
response = client_three.diff(@changed, @info)
|
73
|
+
assert [Conflict::Conflict.new(@third, @first)].eql?(response)
|
74
|
+
|
75
|
+
response = client_one.revert @info
|
76
|
+
assert_equal [], response
|
77
|
+
|
78
|
+
response = client_three.revert @info
|
79
|
+
assert_equal [], response
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class NegativeServerTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
DATA_DIR = './test/data/three/'
|
25
|
+
|
26
|
+
def test_combinations
|
27
|
+
|
28
|
+
@cfg = {:port=>84}
|
29
|
+
@thread = Thread.new do
|
30
|
+
Server::new(@cfg).start
|
31
|
+
end
|
32
|
+
|
33
|
+
added = File::new(DATA_DIR + "added.diff.txt").to_s
|
34
|
+
deleted = File::new(DATA_DIR + "deleted.diff.txt").to_s
|
35
|
+
info = File::new(DATA_DIR + "conflict.info.txt").to_s
|
36
|
+
|
37
|
+
clients = [{}, {"client"=>""}, {"client"=>" "}, {"client"=>"foo"}]
|
38
|
+
diffs = [{}, {"diff"=>""}, {"diff"=>" "}, {"diff"=>added} ]
|
39
|
+
infos = [{}, {"info"=>""}, {"info"=>" "}, {"info"=>info} ]
|
40
|
+
|
41
|
+
# leaving these out until I can figure out how to make multi-params happen w/ ruby 1.8.4
|
42
|
+
# {"diff"=>[added,deleted]}
|
43
|
+
# {"info"=>[info,info]}
|
44
|
+
# [3, 4, 4]
|
45
|
+
|
46
|
+
# single diff with no changes, single diff w/ no changes,
|
47
|
+
# single diff w/ changes, multi-diff with changes
|
48
|
+
good = [ [3, 1, 3], [3, 2, 3], [3, 3, 3] ]
|
49
|
+
|
50
|
+
# tests all mathematical possibilities
|
51
|
+
clients.each_index do | i |
|
52
|
+
diffs.each_index do | j |
|
53
|
+
infos.each_index do | k |
|
54
|
+
|
55
|
+
body = clients[i].merge(diffs[j]).merge(infos[k])
|
56
|
+
code = send body
|
57
|
+
point = [i, j, k]
|
58
|
+
expected_code = good.index(point) ? 200 : 500
|
59
|
+
assert_equal(expected_code.to_s, code, point.to_s + " -> " + body.to_s)
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@thread.kill
|
66
|
+
@thread.join(5)
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def send body
|
71
|
+
|
72
|
+
req = Net::HTTP::Post.new(Conflict::DIFF_URL)
|
73
|
+
req.set_form_data(body)
|
74
|
+
http = Net::HTTP.new("127.0.0.1", @cfg[:port])
|
75
|
+
res = http.request(req).code
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|