deplomat 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 755ad955bc1aece1a1e633cfee0bad1f93aa02776f0c3e2a17cefe7d18c85b1c
4
- data.tar.gz: e3b92771661140bcec8e9518e3a69b94acd535c39b4ed8096c954e20b1cc0d61
3
+ metadata.gz: 06ea7373755469a175c961d68e8968cbcb183d44a938b50da8f87314a3032318
4
+ data.tar.gz: 6947ac82c80f4f4bc702a21c9d5aa76ba6e03f243376619d266e8771519a74b8
5
5
  SHA512:
6
- metadata.gz: ba8b7c73736aa04d4b411f6dec1008010a3e9d7ac8d109cd416f409fb1aea722490a22a81ddba206d865e7d43d61231b1da6104d1bda2f90a6afee3118a3d613
7
- data.tar.gz: f082cd70ab88e1a7bfbfd77bd6f8f30cb53ba8b270d4aabbf37bc1e17516aa9c19e4216ce2eb76292845beb4aa1e803885a4f5ac71d3329f6004ae741b4de183
6
+ metadata.gz: 757c22b3acfcca212194f2f7d7b2fd0b4f52751d328d88d995517acd85be43404319e8b735fd16dffcf433c2faebeaaf0e1ad41b5247f90a5ded36dd5163880e
7
+ data.tar.gz: 077f00f699e37215daaf96dba5fd2a1c7666697d0f3e9448cf96d095295817d74e54bc050cb1217c73f890d4c6c01029ccc2fdebe208e9db8188514d45549832
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ spec/fixtures/git_repo
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ gem "sys-proctable"
4
4
  gem "colorize"
5
5
 
6
6
  group :development do
7
- gem "bundler", "~> 1.0"
7
+ gem "bundler", "~> 2.0"
8
8
  gem "rspec"
9
9
  end
data/Gemfile.lock CHANGED
@@ -24,10 +24,10 @@ PLATFORMS
24
24
  ruby
25
25
 
26
26
  DEPENDENCIES
27
- bundler (~> 1.0)
27
+ bundler (~> 2.0)
28
28
  colorize
29
29
  rspec
30
30
  sys-proctable
31
31
 
32
32
  BUNDLED WITH
33
- 1.17.2
33
+ 2.0.2
data/LICENSE.txt CHANGED
@@ -1,5 +1,3 @@
1
- Copyright (c) 2016 Roman Snitko
2
-
3
1
  Permission is hereby granted, free of charge, to any person obtaining
4
2
  a copy of this software and associated documentation files (the
5
3
  "Software"), to deal in the Software without restriction, including
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.12
1
+ 0.2.13
data/deplomat.gemspec CHANGED
@@ -1,83 +1,19 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: deplomat 0.2.10 ruby lib
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
3
 
7
- Gem::Specification.new do |s|
8
- s.name = "deplomat".freeze
9
- s.version = "0.2.12"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib".freeze]
13
- s.authors = ["Roman Snitko".freeze]
14
- s.date = "2019-06-16"
15
- s.description = "Stack agnostic deployment system that uses bash and ssh commands".freeze
16
- s.email = "roman.snitko@gmail.com".freeze
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.md",
28
- "Rakefile",
29
- "VERSION",
30
- "deplomat.gemspec",
31
- "examples/simple_deploy.rb",
32
- "lib/deplomat.rb",
33
- "lib/deplomat/directives.rb",
34
- "lib/deplomat/exceptions.rb",
35
- "lib/deplomat/local_node.rb",
36
- "lib/deplomat/node.rb",
37
- "lib/deplomat/remote_node.rb",
38
- "spec/deployment_requisites/1_req.rb",
39
- "spec/deployment_requisites/2_req.rb",
40
- "spec/deployment_requisites/not_a_task.rb",
41
- "spec/directives_spec.rb",
42
- "spec/fixtures/.deployment_requisites_counter",
43
- "spec/fixtures/cleaning/.keep",
44
- "spec/fixtures/dir1/file1",
45
- "spec/fixtures/dir1/file2",
46
- "spec/fixtures/upload1/except1",
47
- "spec/fixtures/upload1/uploaded_file1",
48
- "spec/fixtures/upload1/uploaded_file2",
49
- "spec/local_node_spec.rb",
50
- "spec/node_spec.rb",
51
- "spec/remote_node_spec.rb",
52
- "spec/spec_helper.rb"
53
- ]
54
- s.homepage = "http://github.com/snitko/deplomat".freeze
55
- s.licenses = ["MIT".freeze]
56
- s.rubygems_version = "2.7.6".freeze
57
- s.summary = "Stack agnostic deployment system that uses bash and ssh commands".freeze
58
-
59
- if s.respond_to? :specification_version then
60
- s.specification_version = 4
61
-
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<sys-proctable>.freeze, [">= 0"])
64
- s.add_runtime_dependency(%q<colorize>.freeze, [">= 0"])
65
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
66
- s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
67
- s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
68
- else
69
- s.add_dependency(%q<sys-proctable>.freeze, [">= 0"])
70
- s.add_dependency(%q<colorize>.freeze, [">= 0"])
71
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
72
- s.add_dependency(%q<jeweler>.freeze, [">= 0"])
73
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
74
- end
75
- else
76
- s.add_dependency(%q<sys-proctable>.freeze, [">= 0"])
77
- s.add_dependency(%q<colorize>.freeze, [">= 0"])
78
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
79
- s.add_dependency(%q<jeweler>.freeze, [">= 0"])
80
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "deplomat"
6
+ spec.description = "Stack agnostic deployment system that uses bash and ssh commands".freeze
7
+ spec.summary = "Deplomat".freeze
8
+ spec.homepage = "https://gitlab.com/hodlhodl-public/deplomat"
9
+ spec.license = "MIT"
10
+ spec.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if spec.respond_to? :required_rubygems_version=
11
+ spec.require_paths = ["lib".freeze]
12
+ spec.authors = ["romanitup".freeze]
13
+ spec.extra_rdoc_files = [ "LICENSE.txt", "README.md"]
14
+ spec.version = File.readlines(File.expand_path(File.dirname(__FILE__)) + "/VERSION")[0]
15
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
81
17
  end
18
+ spec.require_paths = ["lib"]
82
19
  end
83
-
@@ -66,14 +66,14 @@ def load_requisites!(counter, requisites_path: "#{Dir.pwd}/deployment_requisites
66
66
  log_requisites_count = "Checking #{requisites_path} dir for requisites..."
67
67
  files = Dir["#{requisites_path}/*.rb"].map do |fn|
68
68
  number = fn.split("/").last.match(/\A\d+_/).to_a.first&.chomp("_")
69
- number ? [number, fn] : nil
69
+ number ? [number.to_i, fn] : nil
70
70
  end
71
71
 
72
72
  if files
73
73
  files = files.compact # ignore files that don't start with a number
74
74
  .sort { |x,y| x.first <=> y.first } # Sort files according to the number in front of their names
75
75
  .map { |fn| fn.last } # lose the folded Array we used to store the consecutive requisite number
76
- .slice(counter..-1) # lose files whose consecutive requisite number is below or equals the counter
76
+ .slice(counter..-1) # lose files whose consecutive requisite number is below or equals the counter
77
77
  end
78
78
 
79
79
  if files && files.size > 0
@@ -85,7 +85,7 @@ def load_requisites!(counter, requisites_path: "#{Dir.pwd}/deployment_requisites
85
85
  else
86
86
  log_requisites_count += "no files found"
87
87
  end
88
- log << log_requisites_count
88
+ log.unshift log_requisites_count
89
89
 
90
90
  return { counter: (files ? (counter + files.size) : 0), log: log }
91
91
 
@@ -24,8 +24,7 @@ module Deplomat
24
24
  end
25
25
  @pids.compact!
26
26
  if @pids.empty?
27
- log("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.", color: "red")
28
- exit 1
27
+ raise Error.new("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.", color: "red")
29
28
  elsif @pids.length > 1
30
29
  log("Connected with ssh, host #{host}, but looks like another connection has been opened before...", color: "white")
31
30
  log("connection pids: #{@pids.join(", ")}. We'll be closing them all when finished.", color: "white")
metadata CHANGED
@@ -1,87 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
- - Roman Snitko
7
+ - romanitup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sys-proctable
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: colorize
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
55
- - !ruby/object:Gem::Dependency
56
- name: jeweler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description: Stack agnostic deployment system that uses bash and ssh commands
84
- email: roman.snitko@gmail.com
14
+ email:
85
15
  executables: []
86
16
  extensions: []
87
17
  extra_rdoc_files:
@@ -89,12 +19,12 @@ extra_rdoc_files:
89
19
  - README.md
90
20
  files:
91
21
  - ".document"
22
+ - ".gitignore"
92
23
  - ".rspec"
93
24
  - Gemfile
94
25
  - Gemfile.lock
95
26
  - LICENSE.txt
96
27
  - README.md
97
- - Rakefile
98
28
  - VERSION
99
29
  - deplomat.gemspec
100
30
  - examples/simple_deploy.rb
@@ -104,22 +34,7 @@ files:
104
34
  - lib/deplomat/local_node.rb
105
35
  - lib/deplomat/node.rb
106
36
  - lib/deplomat/remote_node.rb
107
- - spec/deployment_requisites/1_req.rb
108
- - spec/deployment_requisites/2_req.rb
109
- - spec/deployment_requisites/not_a_task.rb
110
- - spec/directives_spec.rb
111
- - spec/fixtures/.deployment_requisites_counter
112
- - spec/fixtures/cleaning/.keep
113
- - spec/fixtures/dir1/file1
114
- - spec/fixtures/dir1/file2
115
- - spec/fixtures/upload1/except1
116
- - spec/fixtures/upload1/uploaded_file1
117
- - spec/fixtures/upload1/uploaded_file2
118
- - spec/local_node_spec.rb
119
- - spec/node_spec.rb
120
- - spec/remote_node_spec.rb
121
- - spec/spec_helper.rb
122
- homepage: http://github.com/snitko/deplomat
37
+ homepage: https://gitlab.com/hodlhodl-public/deplomat
123
38
  licenses:
124
39
  - MIT
125
40
  metadata: {}
@@ -141,5 +56,5 @@ requirements: []
141
56
  rubygems_version: 3.0.3
142
57
  signing_key:
143
58
  specification_version: 4
144
- summary: Stack agnostic deployment system that uses bash and ssh commands
59
+ summary: Deplomat
145
60
  test_files: []
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
- gem.name = "deplomat"
18
- gem.homepage = "http://github.com/snitko/deplomat"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Stack agnostic deployment system that uses bash and ssh commands}
21
- gem.description = %Q{Stack agnostic deployment system that uses bash and ssh commands}
22
- gem.email = "roman.snitko@gmail.com"
23
- gem.authors = ["Roman Snitko"]
24
- # dependencies defined in Gemfile
25
- end
@@ -1,3 +0,0 @@
1
- before_task(:task1, 1) do
2
- $deployment_requisites_test_file1 = true
3
- end
@@ -1,3 +0,0 @@
1
- before_task(:task2, 2) do
2
- $deployment_requisites_test_file2 = true
3
- end
File without changes
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "directives" do
4
-
5
- before(:each) do
6
- $deplomat_tasks = []
7
- end
8
-
9
- it "executes arbitrary ruby code in a particular environment" do
10
- $env = 'staging'
11
- expect(self).to receive(:hello).exactly(1).times
12
- execute_in(env: 'staging') { hello() }
13
- execute_in(env: 'production') { hello() }
14
- end
15
-
16
- it "creates a partial" do
17
- partial("hello_partial") { hello() }
18
- expect($partials["hello_partial"][:block]).to be_kind_of(Proc)
19
- end
20
-
21
- it "executes a partial" do
22
- expect(self).to receive(:hello).with("hello").exactly(1).times
23
- partial("hello_partial") { |args| hello(args[:x]) }
24
- execute_partial "hello_partial", x: 'hello'
25
- end
26
-
27
- it "executes tasks consecutively, running before and after callbacks" do
28
-
29
- $out = ""
30
- def task1; $out += "task1"; end
31
- def task2; $out += "task2"; end
32
- def task3; $out += ",task3"; end
33
-
34
- before_task(:task1, 1) { $out += "before_task1:" }
35
- after_task(:task1, 2) { $out += ":after_task1," }
36
- before_task(:task2, 3) { $out += "before_task2:" }
37
- after_task(:task2, 4) { $out += ":after_task2" }
38
- before_task(:task4, 5) { $out += "before_task4:" }
39
- after_task(:task4, 6) { $out += ":after_task4" }
40
-
41
- add_task :task1, :task2, :task3
42
-
43
- execute_tasks!
44
- expect($out).to eq("before_task1:task1:after_task1,before_task2:task2:after_task2,task3")
45
-
46
- end
47
-
48
- it "loads and runs requisites" do
49
-
50
- def task1;end
51
- def task2;end
52
-
53
- add_task :task1, :task2
54
-
55
- result = load_requisites!(1, requisites_path: "#{File.expand_path(File.dirname(__FILE__))}/deployment_requisites")
56
- expect(result[:counter]).to eq(2)
57
- expect(result[:log].last).to eq("Loading requisite: 2_req.rb")
58
- execute_tasks!
59
- expect($deployment_requisites_test_file1).to be_nil
60
- expect($deployment_requisites_test_file2).to be_truthy
61
-
62
- end
63
-
64
- end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,180 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Deplomat::LocalNode do
4
-
5
- before(:each) do
6
- @fixtures_dir = Dir.pwd + "/spec/fixtures"
7
- @localhost = Deplomat::LocalNode.new
8
- @localhost.log_to = []
9
- @localhost.raise_exceptions = false
10
- end
11
-
12
- after(:each) do
13
- FileUtils.rm_r(Dir.glob("#{@fixtures_dir}/dir2/*"))
14
- end
15
-
16
- describe "filesystem operations" do
17
-
18
- it "copies files to another folder" do
19
- @localhost.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
20
- expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_truthy
21
- expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_truthy
22
- end
23
-
24
- it "moves files and dirs to another directory" do
25
- @localhost.move("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
26
- expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_truthy
27
- expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_truthy
28
- expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_truthy
29
- expect(File.exist?("#{@fixtures_dir}/dir1/file1")).to be_falsy
30
- expect(File.exist?("#{@fixtures_dir}/dir1/file2")).to be_falsy
31
- expect(File.exist?("#{@fixtures_dir}/dir1/subdir1")).to be_falsy
32
-
33
- @localhost.move("#{@fixtures_dir}/dir2/*", "#{@fixtures_dir}/dir1/")
34
- expect(File.exist?("#{@fixtures_dir}/dir1/file1")).to be_truthy
35
- expect(File.exist?("#{@fixtures_dir}/dir1/file2")).to be_truthy
36
- expect(File.exist?("#{@fixtures_dir}/dir1/subdir1")).to be_truthy
37
- expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_falsy
38
- expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_falsy
39
- expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_falsy
40
- end
41
-
42
- it "removes files and dirs" do
43
- @localhost.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
44
- @localhost.remove("#{@fixtures_dir}/dir2/*")
45
- expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_falsy
46
- expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_falsy
47
- expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_falsy
48
- end
49
-
50
- it "changes current directory" do
51
- @localhost.cd("/etc")
52
- expect(@localhost.current_path).to eq("/etc/")
53
- expect(-> { @localhost.cd("/non-existent-path") }).to raise_exception(Deplomat::NoSuchPathError)
54
- end
55
-
56
- it "executes commands from the current directory" do
57
- @localhost.cd("#{@fixtures_dir}/dir1")
58
- expect(@localhost.execute("ls")[:out]).to eq("file1\nfile2\nsubdir1\n")
59
- end
60
-
61
- it "creates an empty file" do
62
- @localhost.cd("#{@fixtures_dir}/dir2")
63
- @localhost.touch("myfile")
64
- expect(@localhost.execute("ls")[:out]).to have_files("myfile")
65
- end
66
-
67
- it "creates a directory" do
68
- @localhost.cd("#{@fixtures_dir}/dir2")
69
- @localhost.mkdir("mydir")
70
- expect(@localhost.execute("ls")[:out]).to have_files("mydir")
71
- end
72
-
73
- it "creates a symlink" do
74
- @localhost.cd("#{@fixtures_dir}/dir2")
75
- @localhost.create_symlink("../dir1", "./")
76
- expect(@localhost.execute("ls dir1")[:out]).to have_files("file1", "file2", "subdir1")
77
- end
78
-
79
- end
80
-
81
- describe "handling status and errors" do
82
-
83
- it "returns the status" do
84
- expect(@localhost.execute("ls #{@fixtures_dir}/dir1/")[:status]).to eq(0)
85
- expect(@localhost.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status]).to eq(2)
86
- end
87
-
88
- it "raises execution error when command fails" do
89
- @localhost.raise_exceptions = true
90
- expect( -> { @localhost.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status] }).to raise_exception(Deplomat::ExecutionError)
91
- end
92
-
93
- end
94
-
95
- describe "cleaning" do
96
-
97
- before(:each) do
98
- @localhost.cd("#{@fixtures_dir}/cleaning")
99
- @localhost.execute("touch file1 file2 file3")
100
- @localhost.execute("mkdir current")
101
- sleep(0.01)
102
- @localhost.execute("mkdir dir1 dir2 dir3")
103
- end
104
-
105
- after(:each) do
106
- @localhost.execute("rm -rf #{@fixtures_dir}/cleaning/*")
107
- end
108
-
109
- it "cleans all the files and dirs in a given directory" do
110
- @localhost.clean
111
- expect(@localhost.execute('ls')[:out]).to be_empty
112
- end
113
-
114
- it "cleans all but last 3 entries in a given directory" do
115
- @localhost.clean(leave: [3, :last])
116
- expect(@localhost.execute('ls')[:out]).to eq("dir1\ndir2\ndir3\n")
117
- end
118
-
119
- it "cleans all, but :except entries in a given directory" do
120
- @localhost.clean(except: ["current"])
121
- expect(@localhost.execute('ls')[:out]).to eq("current\n")
122
- end
123
-
124
- end
125
-
126
- describe "git commands" do
127
-
128
- before(:all) do
129
- @fixtures_dir = Dir.pwd + "/spec/fixtures"
130
- @localhost_git = Deplomat::LocalNode.new
131
- @localhost_git.log_to = [:stdout]
132
- @localhost_git.cd(@fixtures_dir)
133
- @localhost_git.mkdir("git_repo")
134
- @localhost_git.cd("git_repo")
135
- @localhost_git.touch("file1")
136
- @localhost_git.execute("git init && git add .")
137
- @localhost_git.execute("git remote add origin deploy@deplomat-test-node:/home/deploy/deplomat/.git_repo")
138
- @remote_node = Deplomat::RemoteNode.new(host: "deplomat-test-node", user: "deploy")
139
- @remote_node.log_to = [:stdout]
140
- @remote_node.execute("cd ~/deplomat && mkdir .git_repo && cd .git_repo && git --bare init")
141
- @localhost_git.cd("#{@fixtures_dir}/git_repo")
142
- @localhost_git.execute("git commit -m \"Initial commit\"")
143
-
144
- @localhost_git.raise_exceptions = true
145
- @remote_node.raise_exceptions = true
146
- end
147
-
148
- after(:all) do
149
- @remote_node.remove("~/deplomat/.git_repo")
150
- @localhost_git.remove("#{@fixtures_dir}/git_repo")
151
- end
152
-
153
- it "pushes to remote" do
154
- expect(@localhost_git.git_push[:status]).to eq(0)
155
- end
156
-
157
- it "pulls from remote" do
158
- expect(@localhost_git.git_pull[:status]).to eq(0)
159
- end
160
-
161
- it "merges branches" do
162
- @localhost_git.execute("git checkout -b dev1")
163
- @localhost_git.touch("file2")
164
- @localhost_git.execute("git add . && git commit -m \"adding file2\"")
165
- @localhost_git.execute("git checkout master")
166
- expect(@localhost_git.git_merge("dev1", "master")[:status]).to eq(0)
167
- expect(File.exist?("#{@fixtures_dir}/git_repo/file2")).to be_truthy
168
- end
169
-
170
- it "checks out into a branch" do
171
- @localhost_git.execute("git branch dev2")
172
- @localhost_git.touch("file3")
173
- @localhost_git.execute("git add . && git commit -m \"adding file3\"")
174
- @localhost_git.git_checkout("dev2")
175
- expect(File.exist?("#{@fixtures_dir}/git_repo/file3")).to be_falsy
176
- end
177
-
178
- end
179
-
180
- end
data/spec/node_spec.rb DELETED
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Deplomat::Node do
4
-
5
- before(:each) do
6
- @fixtures_dir = Dir.pwd + "/spec/fixtures"
7
- @node = Deplomat::Node.new(logfile: "#{@fixtures_dir}/deplomat.log", log_to: [:file, :stdout])
8
- end
9
-
10
- it "checks if file exists" do
11
- expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_falsey
12
- expect(@node.file_exists?("/non-existent-path")).to be_falsey
13
- FileUtils.touch("#{@fixtures_dir}/existing_file.txt")
14
- expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_truthy
15
- FileUtils.rm("#{@fixtures_dir}/existing_file.txt")
16
- end
17
-
18
- describe "logging" do
19
-
20
- after(:each) do
21
- @node.log_to = []
22
- @node.remove("#{@fixtures_dir}/deplomat.log")
23
- end
24
-
25
- it "logs to the stdout" do
26
- expect($stdout).to receive(:print).exactly(4).times
27
- @node.execute("ls #{@fixtures_dir}/dir1")
28
- end
29
-
30
- it "logs to a log file" do
31
- @node.log_to = [:file]
32
- @node.execute("ls #{@fixtures_dir}/dir1")
33
- log = File.readlines("#{@fixtures_dir}/deplomat.log")
34
- expect(log.size).to eq(4)
35
- end
36
-
37
- it "puts additional messages into the terminal when required" do
38
- expect($stdout).to receive(:print).once.with("hello\n".white)
39
- expect($stdout).to receive(:print).once.with("--> ls #{@fixtures_dir}/dir1\n".white)
40
- expect($stdout).to receive(:print).once.with(" file1\n".light_black)
41
- expect($stdout).to receive(:print).once.with(" file2\n".light_black)
42
- expect($stdout).to receive(:print).once.with(" subdir1\n".light_black)
43
- expect($stdout).to receive(:print).once.with("bye\n".white)
44
- @node.execute("ls #{@fixtures_dir}/dir1", message: ["hello", "bye"])
45
- end
46
-
47
- it "updates requisite counter" do
48
- @node.log_to = []
49
-
50
- requisites_counter_fn = "#{Dir.pwd}/spec/.deployment_requisites_counter"
51
- @node.cd Dir.pwd + "/spec"
52
-
53
- File.open(requisites_counter_fn, "w") { |f| f.puts 1 }
54
- @node.update_requisite_number!(2)
55
- expect(File.readlines(requisites_counter_fn).first.to_i).to eq(2)
56
-
57
- expect(-> { @node.update_requisite_number!(1) }).to raise_exception(SystemExit)
58
-
59
- File.unlink(requisites_counter_fn)
60
- expect(-> { @node.update_requisite_number!(3) }).to raise_exception(SystemExit)
61
- end
62
-
63
- end
64
-
65
- end
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Deplomat::RemoteNode do
4
-
5
- before(:all) do
6
- @fixtures_dir = "/home/deploy/deplomat"
7
- @local_fixtures_dir = Dir.pwd + "/spec/fixtures"
8
- @node = Deplomat::RemoteNode.new(host: "deplomat-test-node", user: "deploy")
9
- @node.log_to = []
10
- end
11
-
12
- before(:each) do
13
- @node.raise_exceptions = true
14
- end
15
-
16
- after(:all) do
17
- @node.close
18
- end
19
-
20
- after(:each) do
21
- @node.raise_exceptions = false
22
- @node.execute("rm -rf #{@fixtures_dir}/dir2/*")
23
- @node.execute("rm -rf #{@fixtures_dir}/uploaded1/*")
24
- @node.execute("rm -rf #{@fixtures_dir}/uploaded2/*")
25
- end
26
-
27
- describe "filesystem operations" do
28
-
29
- it "copies files to another folder" do
30
- @node.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
31
- expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
32
- end
33
-
34
- it "moves files and dirs from one directory into another" do
35
- @node.move("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
36
- expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:out]).to eq("")
37
- expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
38
- @node.move("#{@fixtures_dir}/dir2/*", "#{@fixtures_dir}/dir1/")
39
- expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to eq("")
40
- expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:out]).to have_files("file1", "file2", "subdir1")
41
- end
42
-
43
- it "removes files and dirs" do
44
- @node.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
45
- expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
46
- @node.remove("#{@fixtures_dir}/dir2/*")
47
- expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to eq("")
48
- end
49
-
50
- it "uploads files from localhost to the node" do
51
- @node.upload("#{@local_fixtures_dir}/upload1/*", "#{@fixtures_dir}/uploaded1/", except: 'except1')
52
- expect(@node.execute("ls #{@fixtures_dir}/uploaded1/")[:out]).to have_files("uploaded_file1", "uploaded_file2")
53
- expect(@node.execute("ls #{@fixtures_dir}/uploaded1/")[:out]).to not_have_files("except1")
54
- end
55
-
56
- it "changes current directory" do
57
- #@node.cd("/etc")
58
- #expect(@node.current_path).to eq("/etc/")
59
- expect(-> { @node.cd("/non-existent-path") }).to raise_exception(Deplomat::NoSuchPathError)
60
- end
61
-
62
- it "executes commands from the current directory" do
63
- @node.cd("#{@fixtures_dir}/dir1")
64
- expect(@node.execute("ls")[:out]).to have_files("file1", "file2", "subdir1")
65
- end
66
-
67
- it "creates an empty file" do
68
- @node.cd("#{@fixtures_dir}/dir2")
69
- @node.touch("myfile")
70
- expect(@node.execute("ls")[:out]).to have_files("myfile")
71
- end
72
-
73
- it "creates a directory" do
74
- @node.cd("#{@fixtures_dir}/dir2")
75
- @node.mkdir("mydir")
76
- expect(@node.execute("ls")[:out]).to have_files("mydir")
77
- end
78
-
79
- it "creates a symlink" do
80
- @node.cd("#{@fixtures_dir}/dir2")
81
- @node.create_symlink("../dir1", "./")
82
- expect(@node.execute("ls dir1")[:out]).to have_files("file1", "file2", "subdir1")
83
- end
84
-
85
- it "doesn't log ls command when checking if folder exists in `cd`" do
86
- expect(@node).to receive(:log).with("(deplomat-test-node) --> ls /home/deploy/deplomat/dir2\n", { color: "white"}).exactly(0).times
87
- @node.cd("#{@fixtures_dir}/dir2")
88
- allow(@node).to receive(:log)
89
- end
90
-
91
- end
92
-
93
- describe "handling status and errors" do
94
-
95
- it "returns the status" do
96
- @node.raise_exceptions = false
97
- expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:status]).to eq(0)
98
- expect(@node.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status]).to eq(2)
99
- end
100
-
101
- it "raises execution error when command fails" do
102
- @node.raise_exceptions = true
103
- expect( -> { @node.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status] }).to raise_exception(Deplomat::ExecutionError)
104
- end
105
-
106
- end
107
-
108
- describe "cleaning" do
109
-
110
- before(:each) do
111
- @node.cd("#{@fixtures_dir}/cleaning")
112
- @node.execute("touch file1 file2 file3")
113
- @node.execute("mkdir current")
114
- sleep(0.01)
115
- @node.execute("mkdir dir1 dir2 dir3")
116
- end
117
-
118
- after(:each) do
119
- @node.execute("rm -rf #{@fixtures_dir}/cleaning/*")
120
- end
121
-
122
- it "cleans all the files and dirs in a given directory" do
123
- @node.clean
124
- expect(@node.execute('ls')[:out]).to be_empty
125
- end
126
-
127
- it "cleans all but last 3 entries in a given directory" do
128
- @node.clean(leave: [3, :last])
129
- expect(@node.execute('ls')[:out]).to eq("dir1\ndir2\ndir3\n")
130
- end
131
-
132
- it "cleans all, but :except entries in a given directory" do
133
- @node.clean(except: ["current"])
134
- expect(@node.execute('ls')[:out]).to eq("current\n")
135
- end
136
-
137
- end
138
-
139
- end
data/spec/spec_helper.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'rspec/expectations'
2
- require "fileutils"
3
- require_relative "../lib/deplomat"
4
-
5
- RSpec::Matchers.define :have_files do |*expected|
6
- match do |actual|
7
- actual = actual.split("\n")
8
- actual.pop if actual.last == ""
9
- expected.each do |e|
10
- return false unless actual.include?(e)
11
- end
12
- true
13
- end
14
- failure_message do |actual|
15
- "expected these files in the directory:\n\t#{actual.split("\n").inspect}\nwould include all of these:\n\t#{expected.inspect}"
16
- end
17
- end
18
-
19
- RSpec::Matchers.define :not_have_files do |*expected|
20
- match do |actual|
21
- actual = actual.split("\n")
22
- actual.pop if actual.last == ""
23
- expected.each do |e|
24
- return false if actual.include?(e)
25
- end
26
- true
27
- end
28
- failure_message do |actual|
29
- "expected these files in the directory:\n\t#{actual.split("\n").inspect}\nwould NOT include any of these:\n\t#{expected.inspect}"
30
- end
31
- end