cloner 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require_relative '../lib/cloner'
5
+
6
+ # Mock Rails for testing
7
+ class ::Rails
8
+ def self.root
9
+ Pathname.new(File.expand_path("../", __FILE__))
10
+ end
11
+ def self.env
12
+ "development"
13
+ end
14
+ end
15
+
16
+ class TestDockerCompose < Cloner::Base
17
+ no_commands do
18
+ def rails_path
19
+ File.expand_path("../", __FILE__)
20
+ end
21
+
22
+ def load_env
23
+ require 'net/ssh'
24
+ require 'shellwords'
25
+ require 'active_support/core_ext/object'
26
+ end
27
+
28
+ # Test with mock SSH - no actual connection
29
+ def ssh_host
30
+ 'localhost'
31
+ end
32
+
33
+ def ssh_user
34
+ 'test'
35
+ end
36
+
37
+ def env_from
38
+ "production"
39
+ end
40
+
41
+ # Docker Compose configuration
42
+ def use_docker_compose?
43
+ true
44
+ end
45
+
46
+ def local_docker_compose?
47
+ true
48
+ end
49
+
50
+ def remote_docker_compose?
51
+ true
52
+ end
53
+
54
+ def local_docker_compose_service
55
+ 'testdb'
56
+ end
57
+
58
+ def remote_docker_compose_service
59
+ 'rtdb'
60
+ end
61
+
62
+ def local_docker_compose_path
63
+ Rails.root.parent.to_s
64
+ end
65
+
66
+ def remote_app_path
67
+ '/root/compose/rtrack'
68
+ end
69
+
70
+ def remote_dump_path
71
+ "#{remote_app_path}/tmp_dump"
72
+ end
73
+
74
+ # Mock database configurations
75
+ def read_ar_r_conf
76
+ {
77
+ adapter: "postgresql",
78
+ host: "rtdb",
79
+ database: "rtrack",
80
+ username: "rtrack",
81
+ password: "testpass"
82
+ }.stringify_keys
83
+ end
84
+
85
+ def ar_conf
86
+ {
87
+ adapter: "postgresql",
88
+ host: "localhost",
89
+ database: "test_development",
90
+ username: "testuser",
91
+ password: "testpass"
92
+ }.stringify_keys
93
+ end
94
+
95
+ def ar_to
96
+ ar_conf['database']
97
+ end
98
+
99
+ def verbose?
100
+ true
101
+ end
102
+
103
+ # Override SSH to test without actual connection
104
+ def do_ssh(&block)
105
+ puts "MOCK SSH: Would connect to #{ssh_user}@#{ssh_host}"
106
+ # Create mock SSH session
107
+ mock_ssh = Object.new
108
+ def mock_ssh.exec!(cmd)
109
+ puts "MOCK SSH EXEC: #{cmd}"
110
+ # Return mock responses
111
+ if cmd.include?('.env')
112
+ return "DB_HOST=rtdb\nDB_PORT=5432\nDB_NAME=rtrack\nDB_USER=rtrack\nDB_PASSWORD=testpass\n"
113
+ elsif cmd.include?('mkdir')
114
+ return ""
115
+ elsif cmd.include?('pg_dump')
116
+ return ""
117
+ end
118
+ ""
119
+ end
120
+ def mock_ssh.open_channel(&block)
121
+ mock_channel = Object.new
122
+ def mock_channel.exec(cmd, &cb)
123
+ puts "MOCK CHANNEL EXEC: #{cmd}"
124
+ end
125
+ def mock_channel.on_data(&cb)
126
+ cb.call(nil, "")
127
+ end
128
+ def mock_channel.on_extended_data(&cb)
129
+ end
130
+ def mock_channel.on_request(type, &cb)
131
+ if type == "exit-status"
132
+ data = Object.new
133
+ def data.read_long
134
+ 0
135
+ end
136
+ cb.call(nil, data)
137
+ end
138
+ end
139
+ block.call(mock_channel)
140
+ end
141
+ def mock_ssh.loop
142
+ end
143
+ def mock_ssh.scp
144
+ mock_scp = Object.new
145
+ def mock_scp.download!(from, to, opts = {})
146
+ puts "MOCK SCP: Download #{from} to #{to}"
147
+ end
148
+ mock_scp
149
+ end
150
+ block.call(mock_ssh)
151
+ end
152
+
153
+ # Override ssh_exec! to simplify testing
154
+ def ssh_exec!(ssh, cmd)
155
+ puts "MOCK SSH EXEC!: #{cmd}"
156
+ # Return mock .env content when requested
157
+ if cmd.include?('.env')
158
+ env_content = "DB_HOST=rtdb\nDB_PORT=5432\nDB_NAME=rtrack\nDB_USER=rtrack\nDB_PASSWORD=testpass\n"
159
+ [0, env_content]
160
+ else
161
+ [0, ""]
162
+ end
163
+ end
164
+
165
+ # Override check_ssh_err for testing
166
+ def check_ssh_err(ret)
167
+ # Do nothing in test
168
+ end
169
+
170
+ # Override rsync for testing
171
+ def rsync(from, to)
172
+ puts "MOCK RSYNC: #{from} -> #{to}"
173
+ # Create a dummy backup file for testing
174
+ FileUtils.mkdir_p(pg_path)
175
+ File.write("#{pg_path}/#{db_file_name}.bak", "MOCK BACKUP DATA")
176
+ end
177
+ end
178
+
179
+ desc "test_compose", "Test Docker Compose functionality"
180
+ def test_compose
181
+ load_env
182
+
183
+ puts "=== Testing Docker Compose Integration ==="
184
+ puts "\nConfiguration:"
185
+ puts "- Local Docker Compose: #{local_docker_compose?}"
186
+ puts "- Remote Docker Compose: #{remote_docker_compose?}"
187
+ puts "- Local Service: #{local_docker_compose_service}"
188
+ puts "- Remote Service: #{remote_docker_compose_service}"
189
+
190
+ puts "\n=== Testing pg_bin_path methods ==="
191
+ puts "Local pg_dump command:"
192
+ puts pg_local_bin_path('pg_dump')
193
+
194
+ puts "\nRemote pg_dump command:"
195
+ puts pg_remote_bin_path('pg_dump')
196
+
197
+ puts "\n=== Testing env var reading ==="
198
+ puts "Remote DB Config:"
199
+ puts remote_db_config.inspect
200
+
201
+ puts "\nLocal DB Config:"
202
+ puts local_db_config.inspect
203
+
204
+ puts "\n=== Simulating database clone ==="
205
+ clone_db
206
+
207
+ puts "\n=== Test completed successfully! ==="
208
+ end
209
+ end
210
+
211
+ if __FILE__ == $0
212
+ TestDockerCompose.start(['test_compose'])
213
+ end
@@ -0,0 +1 @@
1
+ MOCK BACKUP DATA
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebtv
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: thor
@@ -87,16 +86,20 @@ executables: []
87
86
  extensions: []
88
87
  extra_rdoc_files: []
89
88
  files:
89
+ - ".env"
90
90
  - ".gitignore"
91
91
  - ".ruby-version"
92
+ - CLAUDE.md
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
96
97
  - cloner.gemspec
98
+ - compose.yml
97
99
  - lib/cloner.rb
98
100
  - lib/cloner/ar.rb
99
101
  - lib/cloner/base.rb
102
+ - lib/cloner/docker_compose.rb
100
103
  - lib/cloner/internal.rb
101
104
  - lib/cloner/mongodb.rb
102
105
  - lib/cloner/mysql.rb
@@ -106,12 +109,15 @@ files:
106
109
  - lib/cloner/version.rb
107
110
  - lib/generators/cloner_generator.rb
108
111
  - lib/generators/templates/cloner_base.template
112
+ - lib/generators/templates/cloner_docker_compose.thor.erb
109
113
  - lib/generators/templates/cloner_extend.thor.erb
114
+ - test/dl_compose_test.thor
115
+ - test/test_docker_compose.rb
116
+ - test/tmp/dump/cloner.bak
110
117
  homepage: https://github.com/rs-pro/cloner
111
118
  licenses:
112
119
  - MIT
113
120
  metadata: {}
114
- post_install_message:
115
121
  rdoc_options: []
116
122
  require_paths:
117
123
  - lib
@@ -126,8 +132,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  - !ruby/object:Gem::Version
127
133
  version: '0'
128
134
  requirements: []
129
- rubygems_version: 3.1.6
130
- signing_key:
135
+ rubygems_version: 3.6.9
131
136
  specification_version: 4
132
137
  summary: Easily clone your production Mongoid database and files for local development
133
- test_files: []
138
+ test_files:
139
+ - test/dl_compose_test.thor
140
+ - test/test_docker_compose.rb
141
+ - test/tmp/dump/cloner.bak