ghost 0.3.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/LICENSE +1 -1
  2. data/bin/ghost +2 -130
  3. data/lib/ghost.rb +3 -16
  4. data/lib/ghost/cli.rb +60 -0
  5. data/lib/ghost/cli/task.rb +71 -0
  6. data/lib/ghost/cli/task/add.rb +25 -0
  7. data/lib/ghost/cli/task/delete.rb +30 -0
  8. data/lib/ghost/cli/task/empty.rb +18 -0
  9. data/lib/ghost/cli/task/export.rb +19 -0
  10. data/lib/ghost/cli/task/help.rb +41 -0
  11. data/lib/ghost/cli/task/import.rb +25 -0
  12. data/lib/ghost/cli/task/list.rb +40 -0
  13. data/lib/ghost/host.rb +34 -0
  14. data/lib/ghost/store.rb +12 -0
  15. data/lib/ghost/store/dscl_store.rb +71 -0
  16. data/lib/ghost/store/hosts_file_store.rb +123 -0
  17. data/lib/ghost/tokenized_file.rb +65 -0
  18. data/lib/ghost/version.rb +3 -0
  19. data/spec/ghost/cli/task/add_spec.rb +80 -0
  20. data/spec/ghost/cli/task/delete_spec.rb +20 -0
  21. data/spec/ghost/cli/task/empty_spec.rb +19 -0
  22. data/spec/ghost/cli/task/export_spec.rb +16 -0
  23. data/spec/ghost/cli/task/help_spec.rb +36 -0
  24. data/spec/ghost/cli/task/import_spec.rb +56 -0
  25. data/spec/ghost/cli/task/list_spec.rb +50 -0
  26. data/spec/ghost/cli_spec.rb +22 -0
  27. data/spec/ghost/host_spec.rb +36 -0
  28. data/spec/ghost/store/dscl_store_spec.rb +153 -0
  29. data/spec/ghost/store/hosts_file_store_spec.rb +316 -0
  30. data/spec/ghost/store_spec.rb +2 -0
  31. data/spec/ghost/tokenized_file_spec.rb +131 -0
  32. data/spec/spec_helper.rb +4 -2
  33. data/spec/support/cli.rb +29 -0
  34. data/spec/support/resolv.rb +15 -0
  35. metadata +91 -27
  36. data/Rakefile +0 -28
  37. data/TODO +0 -0
  38. data/bin/ghost-ssh +0 -132
  39. data/lib/ghost/linux-host.rb +0 -158
  40. data/lib/ghost/mac-host.rb +0 -116
  41. data/lib/ghost/ssh_config.rb +0 -110
  42. data/spec/etc_hosts_spec.rb +0 -190
  43. data/spec/ghost_spec.rb +0 -151
  44. data/spec/spec.opts +0 -1
  45. data/spec/ssh_config_spec.rb +0 -80
  46. data/spec/ssh_config_template +0 -11
@@ -1,151 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- require 'ghost'
3
-
4
- # Warning: these tests will delete all hostnames in the system. Please back them up first
5
-
6
- Ghost::Host.empty!
7
-
8
- describe Ghost::Host, ".list" do
9
- after(:each) { Ghost::Host.empty! }
10
-
11
- it "should return an array" do
12
- Ghost::Host.list.should be_instance_of(Array)
13
- end
14
-
15
- it "should contain instances of Ghost::Host" do
16
- Ghost::Host.add('ghost-test-hostname.local')
17
- Ghost::Host.list.first.should be_instance_of(Ghost::Host)
18
- end
19
- end
20
-
21
- describe Ghost::Host do
22
- after(:each) { Ghost::Host.empty! }
23
-
24
- it "should have an IP" do
25
- hostname = 'ghost-test-hostname.local'
26
-
27
- Ghost::Host.add(hostname)
28
- host = Ghost::Host.list.first
29
- host.ip.should eql('127.0.0.1')
30
-
31
- Ghost::Host.empty!
32
-
33
- ip = '169.254.23.121'
34
- host = Ghost::Host.add(hostname, ip)
35
- host.ip.should eql(ip)
36
- end
37
-
38
- it "should have a hostname" do
39
- hostname = 'ghost-test-hostname.local'
40
-
41
- Ghost::Host.add(hostname)
42
- host = Ghost::Host.list.first
43
- host.hostname.should eql(hostname)
44
-
45
- Ghost::Host.empty!
46
-
47
- ip = '169.254.23.121'
48
- Ghost::Host.add(hostname, ip)
49
- host.hostname.should eql(hostname)
50
- end
51
-
52
- it ".to_s should return hostname" do
53
- hostname = 'ghost-test-hostname.local'
54
-
55
- Ghost::Host.add(hostname)
56
- host = Ghost::Host.list.first
57
- host.to_s.should eql(hostname)
58
- end
59
- end
60
-
61
- describe Ghost::Host, "finder methods" do
62
- after(:all) { Ghost::Host.empty! }
63
- before(:all) do
64
- Ghost::Host.add('abc.local')
65
- Ghost::Host.add('def.local')
66
- Ghost::Host.add('efg.local', '10.2.2.4')
67
- end
68
-
69
- it "should return valid Ghost::Host when searching for host name" do
70
- Ghost::Host.find_by_host('abc.local').should be_instance_of(Ghost::Host)
71
- end
72
-
73
- end
74
-
75
- describe Ghost::Host, ".add" do
76
- after(:each) { Ghost::Host.empty! }
77
-
78
- it "should return Ghost::Host object when passed hostname" do
79
- Ghost::Host.add('ghost-test-hostname.local').should be_instance_of(Ghost::Host)
80
- end
81
-
82
- it "should return Ghost::Host object when passed hostname" do
83
- Ghost::Host.add('ghost-test-hostname.local', '10.0.0.2').should be_instance_of(Ghost::Host)
84
- end
85
-
86
- it "should raise error if hostname already exists and not add a duplicate" do
87
- Ghost::Host.empty!
88
- Ghost::Host.add('ghost-test-hostname.local')
89
- lambda { Ghost::Host.add('ghost-test-hostname.local') }.should raise_error
90
- Ghost::Host.list.should have(1).thing
91
- end
92
-
93
- it "should overwrite existing hostname if forced" do
94
- hostname = 'ghost-test-hostname.local'
95
-
96
- Ghost::Host.empty!
97
- Ghost::Host.add(hostname)
98
-
99
- Ghost::Host.list.first.hostname.should eql(hostname)
100
- Ghost::Host.list.first.ip.should eql('127.0.0.1')
101
-
102
- Ghost::Host.add(hostname, '10.0.0.1', true)
103
- Ghost::Host.list.first.hostname.should eql(hostname)
104
- Ghost::Host.list.first.ip.should eql('10.0.0.1')
105
-
106
- Ghost::Host.list.should have(1).thing
107
- end
108
-
109
- it "should add a hostname using second hostname's ip" do
110
- hostname = 'ghost-test-hostname.local'
111
- alias_hostname = 'ghost-test-alias-hostname.local'
112
-
113
- Ghost::Host.empty!
114
-
115
- Ghost::Host.add(hostname)
116
- Ghost::Host.add(alias_hostname, hostname)
117
-
118
- Ghost::Host.list.last.ip.should eql(Ghost::Host.list.first.ip)
119
- end
120
-
121
- it "should raise SocketError if it can't find hostname's ip" do
122
- Ghost::Host.empty!
123
- lambda { Ghost::Host.add('ghost-test-alias-hostname.google', 'google') }.should raise_error(SocketError)
124
- end
125
- end
126
-
127
- describe Ghost::Host, ".empty!" do
128
- it "should empty the hostnames" do
129
- Ghost::Host.add('ghost-test-hostname.local') # add a hostname to be sure
130
- Ghost::Host.empty!
131
- Ghost::Host.list.should have(0).things
132
- end
133
- end
134
-
135
- describe Ghost::Host, ".delete_matching" do
136
- it "should delete matching hostnames" do
137
- keep = 'ghost-test-hostname-keep.local'
138
- Ghost::Host.add(keep)
139
- Ghost::Host.add('ghost-test-hostname-match1.local')
140
- Ghost::Host.add('ghost-test-hostname-match2.local')
141
- Ghost::Host.delete_matching('match')
142
- Ghost::Host.list.should have(1).thing
143
- Ghost::Host.list.first.hostname.should eql(keep)
144
- end
145
- end
146
-
147
-
148
- describe Ghost::Host, ".backup and", Ghost::Host, ".restore" do
149
- it "should return a yaml file of all hosts and IPs when backing up"
150
- it "should empty the hosts and restore only the ones in given yaml"
151
- end
@@ -1 +0,0 @@
1
- --colour
@@ -1,80 +0,0 @@
1
- require 'ghost/ssh_config'
2
-
3
- $ssh_config_template = File.expand_path(File.join(File.dirname(__FILE__), "ssh_config_template"))
4
- $ssh_config_file = File.expand_path(File.join(File.dirname(__FILE__), "ssh_config"))
5
-
6
- describe Ghost::SshConfig do
7
- before(:all) do
8
- class Ghost::SshConfig
9
- @@ssh_config = $ssh_config_file
10
- end
11
- end
12
- before { `cp #{$ssh_config_template.inspect} #{$ssh_config_file.inspect}` }
13
- after { `rm -f #{$ssh_config_file.inspect}` }
14
-
15
- subject do
16
- Ghost::SshConfig
17
- end
18
-
19
- it "has an Host" do
20
- subject.empty!
21
-
22
- host = "miami-b01"
23
- hostname = "192.168.227.128"
24
- user = "root"
25
- port = "389"
26
-
27
- subject.add(
28
- :host => host,
29
- :hostname => hostname,
30
- :user => user,
31
- :port => port)
32
-
33
- config = subject.list.first
34
- config.host.should eql(host)
35
- config.hostname.should eql(hostname)
36
- config.user.should eql(user)
37
- config.port.should eql(port)
38
- end
39
-
40
- describe '#list' do
41
- it "returns an array" do
42
- subject.list.should be_instance_of(Array)
43
- end
44
-
45
- it "contains instances of Ghost::SshConfig" do
46
- subject.empty!
47
- subject.add(
48
- :host => "miami-b01",
49
- :hostname => "192.168.227.128",
50
- :user => "root",
51
- :port => "39")
52
-
53
- config = subject.list
54
-
55
- (config = subject.list.first).should be_instance_of(Ghost::SshConfig)
56
-
57
- config.host.should eql("miami-b01")
58
- config.hostname.should eql("192.168.227.128")
59
- config.user.should eql("root")
60
- config.port.should eql("39")
61
- end
62
-
63
- it "parses the .ssh/config format" do
64
- configs = Ghost::SshConfig.list
65
- configs.should have(3).items
66
-
67
- configs[0].host.should eql("example1")
68
- configs[0].hostname.should eql("192.168.227.128")
69
- configs[0].user.should eql("root")
70
-
71
- configs[1].host.should eql("example2")
72
- configs[1].hostname.should eql("example2.webbynode.com")
73
- configs[1].user.should eql("root")
74
- configs[1].port.should eql("2022")
75
-
76
- configs[2].host.should eql("example3")
77
- configs[2].hostname.should eql("10.0.0.1")
78
- end
79
- end
80
- end
@@ -1,11 +0,0 @@
1
- Host example1
2
- HostName 192.168.227.128
3
- User root
4
-
5
- Host example2
6
- HostName example2.webbynode.com
7
- User root
8
- Port 2022
9
-
10
- Host example3
11
- HostName 10.0.0.1