bard 1.4.8 → 1.4.9
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +22 -0
- data/Gemfile +4 -0
- data/bard.gemspec +3 -2
- data/lib/bard/git.rb +5 -1
- data/lib/bard/provision/repo.rb +21 -0
- data/lib/bard/provision/ssh.rb +21 -0
- data/lib/bard/server.rb +2 -2
- data/lib/bard/version.rb +1 -1
- data/spec/bard/cli/ci_spec.rb +139 -0
- data/spec/bard/cli/command_spec.rb +50 -0
- data/spec/bard/cli/data_spec.rb +77 -0
- data/spec/bard/cli/deploy_spec.rb +202 -0
- data/spec/bard/cli/hurt_spec.rb +23 -0
- data/spec/bard/cli/install_spec.rb +25 -0
- data/spec/bard/cli/master_key_spec.rb +52 -0
- data/spec/bard/cli/new_spec.rb +60 -0
- data/spec/bard/cli/open_spec.rb +67 -0
- data/spec/bard/cli/ping_spec.rb +47 -0
- data/spec/bard/cli/provision_spec.rb +42 -0
- data/spec/bard/cli/run_spec.rb +51 -0
- data/spec/bard/cli/setup_spec.rb +76 -0
- data/spec/bard/cli/ssh_spec.rb +55 -0
- data/spec/bard/cli/stage_spec.rb +77 -0
- data/spec/bard/cli/vim_spec.rb +34 -0
- data/spec/bard/command_spec.rb +37 -0
- data/spec/bard/copy_spec.rb +33 -0
- data/spec/bard/git_spec.rb +61 -0
- data/spec/bard/github_pages_spec.rb +80 -0
- data/spec/bard/github_spec.rb +45 -0
- data/spec/bard/ping_spec.rb +31 -0
- data/spec/bard/provision/app_spec.rb +33 -0
- data/spec/bard/provision/apt_spec.rb +39 -0
- data/spec/bard/provision/authorizedkeys_spec.rb +40 -0
- data/spec/bard/provision/data_spec.rb +54 -0
- data/spec/bard/provision/deploy_spec.rb +33 -0
- data/spec/bard/provision/http_spec.rb +57 -0
- data/spec/bard/provision/logrotation_spec.rb +34 -0
- data/spec/bard/provision/masterkey_spec.rb +63 -0
- data/spec/bard/provision/mysql_spec.rb +55 -0
- data/spec/bard/provision/passenger_spec.rb +81 -0
- data/spec/bard/provision/repo_spec.rb +208 -0
- data/spec/bard/provision/rvm_spec.rb +49 -0
- data/spec/bard/provision/ssh_spec.rb +229 -0
- data/spec/bard/provision/swapfile_spec.rb +32 -0
- data/spec/bard/provision/user_spec.rb +103 -0
- data/spec/bard/provision_spec.rb +28 -0
- data/spec/spec_helper.rb +6 -1
- metadata +96 -9
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/master_key"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestMasterKeyCLI < Thor
|
7
|
+
include Bard::CLI::MasterKey
|
8
|
+
|
9
|
+
attr_reader :config, :options
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
@options = {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Bard::CLI::MasterKey do
|
19
|
+
let(:from_server) { double("production") }
|
20
|
+
let(:to_server) { double("local") }
|
21
|
+
let(:config) { { production: from_server, local: to_server } }
|
22
|
+
let(:cli) { TestMasterKeyCLI.new }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(cli).to receive(:config).and_return(config)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#master_key" do
|
29
|
+
it "should have a master_key command" do
|
30
|
+
expect(cli).to respond_to(:master_key)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should copy master key from production to local by default" do
|
34
|
+
allow(config).to receive(:[]).with("production").and_return(from_server)
|
35
|
+
allow(config).to receive(:[]).with("local").and_return(to_server)
|
36
|
+
allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
|
37
|
+
expect(from_server).to receive(:copy_file).with("config/master.key", to: to_server)
|
38
|
+
|
39
|
+
cli.master_key
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should copy master key with custom servers" do
|
43
|
+
staging_server = double("staging")
|
44
|
+
allow(config).to receive(:[]).with("production").and_return(staging_server)
|
45
|
+
allow(config).to receive(:[]).with("local").and_return(to_server)
|
46
|
+
allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
|
47
|
+
expect(staging_server).to receive(:copy_file).with("config/master.key", to: to_server)
|
48
|
+
|
49
|
+
cli.master_key
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/new"
|
4
|
+
|
5
|
+
describe Bard::CLI::New do
|
6
|
+
let(:new_cli) { Bard::CLI::New.new(double("cli")) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(new_cli).to receive(:puts)
|
10
|
+
allow(new_cli).to receive(:exit)
|
11
|
+
allow(new_cli).to receive(:run!)
|
12
|
+
allow(new_cli).to receive(:green).and_return("")
|
13
|
+
allow(new_cli).to receive(:red).and_return("")
|
14
|
+
allow(new_cli).to receive(:yellow).and_return("")
|
15
|
+
allow(File).to receive(:read).and_return("master_key_content")
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#new" do
|
19
|
+
context "with invalid project name" do
|
20
|
+
before do
|
21
|
+
allow(new_cli).to receive(:create_project)
|
22
|
+
allow(new_cli).to receive(:push_to_github)
|
23
|
+
allow(new_cli).to receive(:stage)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should reject names starting with uppercase" do
|
27
|
+
expect(new_cli).to receive(:puts).with(/Invalid project name/)
|
28
|
+
expect(new_cli).to receive(:exit).with(1)
|
29
|
+
|
30
|
+
new_cli.new("InvalidProject")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should reject names with special characters" do
|
34
|
+
expect(new_cli).to receive(:puts).with(/Invalid project name/)
|
35
|
+
expect(new_cli).to receive(:exit).with(1)
|
36
|
+
|
37
|
+
new_cli.new("invalid-project")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should reject names starting with numbers" do
|
41
|
+
expect(new_cli).to receive(:puts).with(/Invalid project name/)
|
42
|
+
expect(new_cli).to receive(:exit).with(1)
|
43
|
+
|
44
|
+
new_cli.new("1invalidproject")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#ruby_version" do
|
50
|
+
it "returns the ruby version" do
|
51
|
+
expect(new_cli.send(:ruby_version)).to eq("ruby-3.4.2")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#template_path" do
|
56
|
+
it "returns the path to the rails template" do
|
57
|
+
expect(new_cli.send(:template_path)).to match(/new_rails_template\.rb$/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/open"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestOpenCLI < Thor
|
7
|
+
include Bard::CLI::Open
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def project_name
|
17
|
+
"test_project"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Bard::CLI::Open do
|
22
|
+
let(:server) { double("server", ping: ["https://example.com"]) }
|
23
|
+
let(:config) { { production: server } }
|
24
|
+
let(:cli) { TestOpenCLI.new }
|
25
|
+
|
26
|
+
before do
|
27
|
+
allow(cli).to receive(:config).and_return(config)
|
28
|
+
allow(cli).to receive(:exec)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#open" do
|
32
|
+
it "should have an open command" do
|
33
|
+
expect(cli).to respond_to(:open)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should open production server URL by default" do
|
37
|
+
expect(cli).to receive(:exec).with("xdg-open https://example.com")
|
38
|
+
|
39
|
+
cli.open
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should open specified server URL" do
|
43
|
+
staging_server = double("staging", ping: ["https://staging.example.com"])
|
44
|
+
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
45
|
+
|
46
|
+
expect(cli).to receive(:exec).with("xdg-open https://staging.example.com")
|
47
|
+
|
48
|
+
cli.open(:staging)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should open CI URL when server is ci" do
|
52
|
+
expect(cli).to receive(:exec).with("xdg-open https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
|
53
|
+
|
54
|
+
cli.open(:ci)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#open_url" do
|
59
|
+
it "returns CI URL for ci server" do
|
60
|
+
expect(cli.send(:open_url, :ci)).to eq("https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns server ping URL for other servers" do
|
64
|
+
expect(cli.send(:open_url, :production)).to eq("https://example.com")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/ping"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestPingCLI < Thor
|
7
|
+
include Bard::CLI::Ping
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Bard::CLI::Ping do
|
18
|
+
let(:server) { double("server", ping: ["https://example.com"]) }
|
19
|
+
let(:config) { { production: server } }
|
20
|
+
let(:cli) { TestPingCLI.new }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(cli).to receive(:config).and_return(config)
|
24
|
+
allow(cli).to receive(:puts)
|
25
|
+
allow(cli).to receive(:exit)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#ping" do
|
29
|
+
it "should have a ping command" do
|
30
|
+
expect(cli).to respond_to(:ping)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call Bard::Ping with the server" do
|
34
|
+
expect(Bard::Ping).to receive(:call).and_return([])
|
35
|
+
|
36
|
+
cli.ping
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should print down URLs when they exist" do
|
40
|
+
down_urls = ["https://down.example.com"]
|
41
|
+
allow(Bard::Ping).to receive(:call).and_return(down_urls)
|
42
|
+
expect(cli).to receive(:puts).with("https://down.example.com is down!")
|
43
|
+
|
44
|
+
cli.ping
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/provision"
|
4
|
+
|
5
|
+
describe Bard::CLI::Provision do
|
6
|
+
let(:config) { { production: double("production", ssh: "user@example.com") } }
|
7
|
+
let(:provision_cli) { Bard::CLI::Provision.new(double("cli")) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(provision_cli).to receive(:config).and_return(config)
|
11
|
+
allow(provision_cli).to receive(:options).and_return({ steps: ["SSH", "User"] })
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "STEPS constant" do
|
15
|
+
it "defines the provisioning steps" do
|
16
|
+
expect(Bard::CLI::Provision::STEPS).to include("SSH", "User", "Apt", "MySQL", "Deploy")
|
17
|
+
expect(Bard::CLI::Provision::STEPS).to be_a(Array)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#provision" do
|
22
|
+
it "should run provision steps" do
|
23
|
+
expect(Bard::Provision).to receive(:const_get).with("SSH").and_return(double("ssh_step", call: true))
|
24
|
+
expect(Bard::Provision).to receive(:const_get).with("User").and_return(double("user_step", call: true))
|
25
|
+
|
26
|
+
provision_cli.provision
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use production ssh by default" do
|
30
|
+
allow(Bard::Provision).to receive(:const_get).and_return(double("step", call: true))
|
31
|
+
|
32
|
+
provision_cli.provision
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should accept custom ssh_url" do
|
36
|
+
custom_ssh = "root@newserver.com"
|
37
|
+
allow(Bard::Provision).to receive(:const_get).and_return(double("step", call: true))
|
38
|
+
|
39
|
+
provision_cli.provision(custom_ssh)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/run"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestRunCLI < Thor
|
7
|
+
include Bard::CLI::Run
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Bard::CLI::Run do
|
18
|
+
let(:server) { double("server") }
|
19
|
+
let(:config) { { production: server } }
|
20
|
+
let(:cli) { TestRunCLI.new }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(cli).to receive(:config).and_return(config)
|
24
|
+
allow(cli).to receive(:puts)
|
25
|
+
allow(cli).to receive(:exit)
|
26
|
+
allow(cli).to receive(:red).and_return("")
|
27
|
+
allow(cli).to receive(:yellow).and_return("")
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#run" do
|
31
|
+
it "should have a run command" do
|
32
|
+
expect(cli).to respond_to(:run)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should run command on production server" do
|
36
|
+
expect(server).to receive(:run!).with("ls -la", verbose: true)
|
37
|
+
|
38
|
+
cli.run("ls", "-la")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle command errors" do
|
42
|
+
error = Bard::Command::Error.new("Command failed")
|
43
|
+
allow(server).to receive(:run!).and_raise(error)
|
44
|
+
|
45
|
+
expect(cli).to receive(:puts).with(/Running command failed/)
|
46
|
+
expect(cli).to receive(:exit).with(1)
|
47
|
+
|
48
|
+
cli.run("failing-command")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/setup"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestSetupCLI < Thor
|
7
|
+
include Bard::CLI::Setup
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def project_name
|
17
|
+
"test_project"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Bard::CLI::Setup do
|
22
|
+
let(:cli) { TestSetupCLI.new }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(Dir).to receive(:pwd).and_return("/home/user/project")
|
26
|
+
allow(File).to receive(:exist?).and_return(false)
|
27
|
+
allow(cli).to receive(:system)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#setup" do
|
31
|
+
it "should have a setup command" do
|
32
|
+
expect(cli).to respond_to(:setup)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create nginx common config" do
|
36
|
+
expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/snippets\/common\.conf/)
|
37
|
+
expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project/)
|
38
|
+
expect(cli).to receive(:system).with(/sudo ln -sf/)
|
39
|
+
expect(cli).to receive(:system).with("sudo service nginx restart")
|
40
|
+
|
41
|
+
cli.setup
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#nginx_server_name" do
|
46
|
+
let(:production_server) { double("production", ping: ["https://example.com"]) }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(cli).to receive(:config).and_return({ production: production_server })
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when RAILS_ENV is production" do
|
53
|
+
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production") }
|
54
|
+
|
55
|
+
it "returns production server names with wildcard" do
|
56
|
+
expect(cli.send(:nginx_server_name)).to eq("*.example.com _")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when RAILS_ENV is staging" do
|
61
|
+
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging") }
|
62
|
+
|
63
|
+
it "returns staging server name" do
|
64
|
+
expect(cli.send(:nginx_server_name)).to eq("test_project.botandrose.com")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when RAILS_ENV is development" do
|
69
|
+
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("development") }
|
70
|
+
|
71
|
+
it "returns localhost server name" do
|
72
|
+
expect(cli.send(:nginx_server_name)).to eq("test_project.localhost")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/ssh"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestSSHCLI < Thor
|
7
|
+
include Bard::CLI::SSH
|
8
|
+
|
9
|
+
attr_reader :config, :options
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = {}
|
14
|
+
@options = {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Bard::CLI::SSH do
|
19
|
+
let(:server) { double("server") }
|
20
|
+
let(:config) { { production: server } }
|
21
|
+
let(:cli) { TestSSHCLI.new }
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(cli).to receive(:config).and_return(config)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#ssh" do
|
28
|
+
it "should have an ssh command" do
|
29
|
+
expect(cli).to respond_to(:ssh)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should execute shell on production server by default" do
|
33
|
+
allow(cli).to receive(:options).and_return({ home: false })
|
34
|
+
expect(server).to receive(:exec!).with("exec $SHELL -l", home: false)
|
35
|
+
|
36
|
+
cli.ssh
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should execute shell with home option when specified" do
|
40
|
+
allow(cli).to receive(:options).and_return({ home: true })
|
41
|
+
expect(server).to receive(:exec!).with("exec $SHELL -l", home: true)
|
42
|
+
|
43
|
+
cli.ssh
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should connect to specified server" do
|
47
|
+
staging_server = double("staging")
|
48
|
+
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
49
|
+
allow(cli).to receive(:options).and_return({ home: false })
|
50
|
+
expect(staging_server).to receive(:exec!).with("exec $SHELL -l", home: false)
|
51
|
+
|
52
|
+
cli.ssh(:staging)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/stage"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestStageCLI < Thor
|
7
|
+
include Bard::CLI::Stage
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@config = nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Bard::CLI::Stage do
|
18
|
+
let(:staging_server) { double("staging") }
|
19
|
+
let(:servers) { { production: double("production"), staging: staging_server } }
|
20
|
+
let(:config) { double("config", servers: servers) }
|
21
|
+
let(:cli) { TestStageCLI.new }
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(cli).to receive(:config).and_return(config)
|
25
|
+
allow(cli).to receive(:puts)
|
26
|
+
allow(cli).to receive(:exit)
|
27
|
+
allow(cli).to receive(:run!)
|
28
|
+
allow(cli).to receive(:ping)
|
29
|
+
allow(cli).to receive(:green).and_return("")
|
30
|
+
allow(cli).to receive(:red).and_return("")
|
31
|
+
allow(cli).to receive(:yellow).and_return("")
|
32
|
+
allow(Bard::Git).to receive(:current_branch).and_return("main")
|
33
|
+
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#stage" do
|
37
|
+
it "should have a stage command" do
|
38
|
+
expect(cli).to respond_to(:stage)
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when production server is defined" do
|
42
|
+
it "pushes branch and stages it" do
|
43
|
+
expect(cli).to receive(:run!).with("git push -u origin main", verbose: true)
|
44
|
+
expect(staging_server).to receive(:run!).with("git fetch && git checkout -f origin/main && bin/setup")
|
45
|
+
expect(cli).to receive(:ping).with(:staging)
|
46
|
+
|
47
|
+
cli.stage
|
48
|
+
end
|
49
|
+
|
50
|
+
it "accepts custom branch" do
|
51
|
+
expect(cli).to receive(:run!).with("git push -u origin develop", verbose: true)
|
52
|
+
expect(staging_server).to receive(:run!).with("git fetch && git checkout -f origin/develop && bin/setup")
|
53
|
+
|
54
|
+
cli.stage("develop")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when production server is not defined" do
|
59
|
+
let(:servers) { { staging: staging_server } }
|
60
|
+
|
61
|
+
it "raises an error" do
|
62
|
+
expect { cli.stage }.to raise_error(Thor::Error, /bard stage.*is disabled/)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when command fails" do
|
67
|
+
it "handles errors gracefully" do
|
68
|
+
allow(cli).to receive(:run!).and_raise(Bard::Command::Error.new("Git push failed"))
|
69
|
+
|
70
|
+
expect(cli).to receive(:puts).with(/Running command failed/)
|
71
|
+
expect(cli).to receive(:exit).with(1)
|
72
|
+
|
73
|
+
cli.stage
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/cli"
|
3
|
+
require "bard/cli/vim"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class TestVimCLI < Thor
|
7
|
+
include Bard::CLI::Vim
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Bard::CLI::Vim do
|
11
|
+
let(:cli) { TestVimCLI.new }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(cli).to receive(:exec)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#vim" do
|
18
|
+
it "should have a vim command" do
|
19
|
+
expect(cli).to respond_to(:vim)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should exec vim with git diff files by default" do
|
23
|
+
expect(cli).to receive(:exec).with("vim -p `git diff master --name-only | grep -v sass$ | tac`")
|
24
|
+
|
25
|
+
cli.vim
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should exec vim with specified branch" do
|
29
|
+
expect(cli).to receive(:exec).with("vim -p `git diff develop --name-only | grep -v sass$ | tac`")
|
30
|
+
|
31
|
+
cli.vim("develop")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/command"
|
3
|
+
|
4
|
+
describe Bard::Command do
|
5
|
+
let(:remote) { double("remote", to_sym: :remote, ssh: true, env: nil, path: "/path/to", ssh_key: nil, ssh_uri: "user@example.com", gateway: nil) }
|
6
|
+
|
7
|
+
describe ".run" do
|
8
|
+
it "should run a command locally" do
|
9
|
+
expect(Open3).to receive(:capture3).with("ls -l").and_return(["output", "", 0])
|
10
|
+
Bard::Command.run "ls -l"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should run a command on a remote server" do
|
14
|
+
expect(Open3).to receive(:capture3).with("ssh -tt user@example.com 'cd /path/to && ls -l'").and_return(["output", "", 0])
|
15
|
+
Bard::Command.run "ls -l", on: remote
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".run!" do
|
20
|
+
it "should run a command locally" do
|
21
|
+
expect(Open3).to receive(:capture3).with("ls -l").and_return(["output", "", 0])
|
22
|
+
Bard::Command.run! "ls -l"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise an error if the command fails" do
|
26
|
+
expect(Open3).to receive(:capture3).with("ls -l").and_return(["output", "error", 1])
|
27
|
+
expect { Bard::Command.run! "ls -l" }.to raise_error(Bard::Command::Error)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".exec!" do
|
32
|
+
it "should exec a command locally" do
|
33
|
+
expect_any_instance_of(Bard::Command).to receive(:exec).with("ls -l")
|
34
|
+
Bard::Command.exec! "ls -l"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/copy"
|
3
|
+
|
4
|
+
describe Bard::Copy do
|
5
|
+
let(:production) { double("production", key: :production, scp_uri: "user@example.com:/path/to/file", rsync_uri: "user@example.com:/path/to/", gateway: nil, ssh_key: nil, path: "/path/to") }
|
6
|
+
let(:local) { double("local", key: :local) }
|
7
|
+
|
8
|
+
context ".file" do
|
9
|
+
it "should copy a file from a remote server to the local machine" do
|
10
|
+
expect(Bard::Command).to receive(:run!).with("scp user@example.com:/path/to/file path/to/file", verbose: false)
|
11
|
+
Bard::Copy.file "path/to/file", from: production, to: local
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should copy a file from the local machine to a remote server" do
|
15
|
+
expect(Bard::Command).to receive(:run!).with("scp path/to/file user@example.com:/path/to/file", verbose: false)
|
16
|
+
Bard::Copy.file "path/to/file", from: local, to: production
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context ".dir" do
|
21
|
+
it "should copy a directory from a remote server to the local machine" do
|
22
|
+
allow(production).to receive_message_chain("ssh_uri.port").and_return(22)
|
23
|
+
expect(Bard::Command).to receive(:run!).with("rsync -e'ssh -p22' --delete --info=progress2 -az user@example.com:/path/to/ ./path/", verbose: false)
|
24
|
+
Bard::Copy.dir "path/to", from: production, to: local
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should copy a directory from the local machine to a remote server" do
|
28
|
+
allow(production).to receive_message_chain("ssh_uri.port").and_return(22)
|
29
|
+
expect(Bard::Command).to receive(:run!).with("rsync -e'ssh -p22' --delete --info=progress2 -az ./path/to user@example.com:/path/to/", verbose: false)
|
30
|
+
Bard::Copy.dir "path/to", from: local, to: production
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|