Class: Dpl::Ctx::Test
- Inherits:
-
Cl::Ctx
- Object
- Cl::Ctx
- Dpl::Ctx::Test
- Includes:
- Squiggle
- Defined in:
- lib/dpl/ctx/test.rb
Instance Attribute Summary collapse
-
#cmds ⇒ Object
readonly
Returns the value of attribute cmds.
-
#last_err ⇒ Object
readonly
Returns the value of attribute last_err.
-
#last_out ⇒ Object
readonly
Returns the value of attribute last_out.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #apt_get(name, cmd = name) ⇒ Object
- #apts_get(apts) ⇒ Object
- #build_dir ⇒ Object
- #build_number ⇒ Object
- #chmod(perm, path) ⇒ Object
- #deprecate_opt(key, msg) ⇒ Object
- #encoding(path) ⇒ Object
- #error(message) ⇒ Object
- #except(hash, *keys) ⇒ Object
- #file_size(path) ⇒ Object
- #fold(name) ⇒ Object
- #gem_require(name, version = nil, opts = {}) ⇒ Object
- #gems_require(gems) ⇒ Object
- #git_author_email ⇒ Object
- #git_author_name ⇒ Object
- #git_branch ⇒ Object
- #git_commit_msg ⇒ Object
- #git_dirty? ⇒ Boolean
- #git_log(args) ⇒ Object
- #git_ls_files ⇒ Object
- #git_ls_remote?(url, ref) ⇒ Boolean
- #git_remote_urls ⇒ Object
- #git_rev_parse(ref) ⇒ Object
- #git_sha ⇒ Object
- #git_tag ⇒ Object
- #info(msg) ⇒ Object
-
#initialize ⇒ Test
constructor
A new instance of Test.
- #logger(level = :info) ⇒ Object
- #machine_name ⇒ Object
- #move_files(paths) ⇒ Object
- #mv(src, dest) ⇒ Object
- #node_version ⇒ Object
- #npm_install(name, cmd = name) ⇒ Object
- #npm_version ⇒ Object
- #pip_install(name, cmd = name, version = nil) ⇒ Object
- #print(chars) ⇒ Object
- #repo_name ⇒ Object
- #repo_slug ⇒ Object
- #rm_rf(path) ⇒ Object
- #shell(cmd, opts = {}) ⇒ Object
- #sleep ⇒ Object
- #ssh_keygen(name, file) ⇒ Object
- #success? ⇒ Boolean
- #test? ⇒ Boolean
- #tmp_dir ⇒ Object
- #tty? ⇒ Boolean
- #unmove_files(paths) ⇒ Object
- #validate_runtimes(runtimes) ⇒ Object
- #warn(msg) ⇒ Object
- #which(cmd) ⇒ Object
- #write_file(path, content, chmod = nil) ⇒ Object
- #write_netrc(machine, login, password) ⇒ Object
Methods included from Squiggle
Constructor Details
#initialize ⇒ Test
Returns a new instance of Test.
12 13 14 15 16 17 |
# File 'lib/dpl/ctx/test.rb', line 12 def initialize @cmds = [] @stderr = StringIO.new @stdout = {} super('dpl') end |
Instance Attribute Details
#cmds ⇒ Object (readonly)
Returns the value of attribute cmds.
10 11 12 |
# File 'lib/dpl/ctx/test.rb', line 10 def cmds @cmds end |
#last_err ⇒ Object (readonly)
Returns the value of attribute last_err.
10 11 12 |
# File 'lib/dpl/ctx/test.rb', line 10 def last_err @last_err end |
#last_out ⇒ Object (readonly)
Returns the value of attribute last_out.
10 11 12 |
# File 'lib/dpl/ctx/test.rb', line 10 def last_out @last_out end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/dpl/ctx/test.rb', line 10 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/dpl/ctx/test.rb', line 10 def stdout @stdout end |
Instance Method Details
#apt_get(name, cmd = name) ⇒ Object
34 35 36 |
# File 'lib/dpl/ctx/test.rb', line 34 def apt_get(name, cmd = name) cmds << "[apt:get] #{name} (#{cmd})" end |
#apts_get(apts) ⇒ Object
30 31 32 |
# File 'lib/dpl/ctx/test.rb', line 30 def apts_get(apts) apts.each { |apt| apt_get(*apt) } end |
#build_dir ⇒ Object
103 104 105 |
# File 'lib/dpl/ctx/test.rb', line 103 def build_dir '.' end |
#build_number ⇒ Object
107 108 109 |
# File 'lib/dpl/ctx/test.rb', line 107 def build_number 1 end |
#chmod(perm, path) ⇒ Object
221 222 223 |
# File 'lib/dpl/ctx/test.rb', line 221 def chmod(perm, path) cmds << [:chmod, perm, path].join(' ') end |
#deprecate_opt(key, msg) ⇒ Object
90 91 92 93 |
# File 'lib/dpl/ctx/test.rb', line 90 def deprecate_opt(key, msg) msg = "please use #{msg}" if msg.is_a?(Symbol) warn "Deprecated option #{key} used (#{msg})." end |
#encoding(path) ⇒ Object
183 184 185 |
# File 'lib/dpl/ctx/test.rb', line 183 def encoding(path) 'text' end |
#error(message) ⇒ Object
86 87 88 |
# File 'lib/dpl/ctx/test.rb', line 86 def error() raise Error, end |
#except(hash, *keys) ⇒ Object
244 245 246 |
# File 'lib/dpl/ctx/test.rb', line 244 def except(hash, *keys) hash.reject { |key, _| keys.include?(key) } end |
#file_size(path) ⇒ Object
197 198 199 |
# File 'lib/dpl/ctx/test.rb', line 197 def file_size(path) File.size(path.sub("#{File.('~')}", './home')) end |
#fold(name) ⇒ Object
19 20 21 22 |
# File 'lib/dpl/ctx/test.rb', line 19 def fold(name) cmds << "[fold] #{name}" yield.tap { cmds << "[unfold] #{name}" } end |
#gem_require(name, version = nil, opts = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dpl/ctx/test.rb', line 42 def gem_require(name, version = nil, opts = {}) # not sure why this is needed. bundler should take care of this, but # it does not for octokit for whatever reason require opts[:require] || name rescue nil cmds << "[gem:require] #{name} (#{version}, #{opts})" end |
#gems_require(gems) ⇒ Object
38 39 40 |
# File 'lib/dpl/ctx/test.rb', line 38 def gems_require(gems) gems.each { |gem| gem_require(*gem) } end |
#git_author_email ⇒ Object
123 124 125 |
# File 'lib/dpl/ctx/test.rb', line 123 def 'author email' end |
#git_author_name ⇒ Object
119 120 121 |
# File 'lib/dpl/ctx/test.rb', line 119 def 'author name' end |
#git_branch ⇒ Object
111 112 113 |
# File 'lib/dpl/ctx/test.rb', line 111 def git_branch 'git branch' end |
#git_commit_msg ⇒ Object
115 116 117 |
# File 'lib/dpl/ctx/test.rb', line 115 def git_commit_msg 'commit msg' end |
#git_dirty? ⇒ Boolean
127 128 129 |
# File 'lib/dpl/ctx/test.rb', line 127 def git_dirty? true end |
#git_log(args) ⇒ Object
131 132 133 |
# File 'lib/dpl/ctx/test.rb', line 131 def git_log(args) 'commits' end |
#git_ls_files ⇒ Object
135 136 137 |
# File 'lib/dpl/ctx/test.rb', line 135 def git_ls_files %w(one two) end |
#git_ls_remote?(url, ref) ⇒ Boolean
139 140 141 |
# File 'lib/dpl/ctx/test.rb', line 139 def git_ls_remote?(url, ref) true end |
#git_remote_urls ⇒ Object
143 144 145 |
# File 'lib/dpl/ctx/test.rb', line 143 def git_remote_urls ['git://origin.git'] end |
#git_rev_parse(ref) ⇒ Object
147 148 149 |
# File 'lib/dpl/ctx/test.rb', line 147 def git_rev_parse(ref) "ref: #{ref}" end |
#git_sha ⇒ Object
155 156 157 |
# File 'lib/dpl/ctx/test.rb', line 155 def git_sha 'sha' end |
#git_tag ⇒ Object
151 152 153 |
# File 'lib/dpl/ctx/test.rb', line 151 def git_tag 'tag' end |
#info(msg) ⇒ Object
74 75 76 |
# File 'lib/dpl/ctx/test.rb', line 74 def info(msg) cmds << "[info] #{msg}" end |
#logger(level = :info) ⇒ Object
187 188 189 190 191 |
# File 'lib/dpl/ctx/test.rb', line 187 def logger(level = :info) logger = Logger.new(stderr) logger.level = Logger.const_get(level.to_s.upcase) logger end |
#machine_name ⇒ Object
159 160 161 |
# File 'lib/dpl/ctx/test.rb', line 159 def machine_name 'machine_name' end |
#move_files(paths) ⇒ Object
201 202 203 204 205 |
# File 'lib/dpl/ctx/test.rb', line 201 def move_files(paths) paths.each do |path| mv(path, "/tmp/#{File.basename(path)}") end end |
#mv(src, dest) ⇒ Object
213 214 215 |
# File 'lib/dpl/ctx/test.rb', line 213 def mv(src, dest) cmds << [:mv, src, dest].join(' ') end |
#node_version ⇒ Object
163 164 165 |
# File 'lib/dpl/ctx/test.rb', line 163 def node_version '11.0.0' end |
#npm_install(name, cmd = name) ⇒ Object
49 50 51 |
# File 'lib/dpl/ctx/test.rb', line 49 def npm_install(name, cmd = name) cmds << "[npm:install] #{name} (#{cmd})" end |
#npm_version ⇒ Object
167 168 169 |
# File 'lib/dpl/ctx/test.rb', line 167 def npm_version '1' end |
#pip_install(name, cmd = name, version = nil) ⇒ Object
53 54 55 |
# File 'lib/dpl/ctx/test.rb', line 53 def pip_install(name, cmd = name, version = nil) cmds << "[pip:install] #{name} (#{cmd}, #{version})" end |
#print(chars) ⇒ Object
78 79 80 |
# File 'lib/dpl/ctx/test.rb', line 78 def print(chars) cmds << "[print] #{chars}" end |
#repo_name ⇒ Object
95 96 97 |
# File 'lib/dpl/ctx/test.rb', line 95 def repo_name 'dpl' end |
#repo_slug ⇒ Object
99 100 101 |
# File 'lib/dpl/ctx/test.rb', line 99 def repo_slug 'travis-ci/dpl' end |
#rm_rf(path) ⇒ Object
217 218 219 |
# File 'lib/dpl/ctx/test.rb', line 217 def rm_rf(path) cmds << [:rm_rf, path].join(' ') end |
#shell(cmd, opts = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/dpl/ctx/test.rb', line 62 def shell(cmd, opts = {}) info cmd.msg if cmd.msg? info cmd.echo if cmd.echo? cmds << cmd.cmd return stdout[cmd.key] if stdout.key?(cmd.key) cmd.capture? ? 'captured_stdout' : true end |
#sleep ⇒ Object
180 181 |
# File 'lib/dpl/ctx/test.rb', line 180 def sleep(*) end |
#ssh_keygen(name, file) ⇒ Object
57 58 59 60 |
# File 'lib/dpl/ctx/test.rb', line 57 def ssh_keygen(name, file) File.open(file, 'w+') { |f| f.write('private-key') } File.open("#{file}.pub", 'w+') { |f| f.write('ssh-rsa public-key') } end |
#success? ⇒ Boolean
70 71 72 |
# File 'lib/dpl/ctx/test.rb', line 70 def success? true end |
#test? ⇒ Boolean
193 194 195 |
# File 'lib/dpl/ctx/test.rb', line 193 def test? true end |
#tmp_dir ⇒ Object
175 176 177 178 |
# File 'lib/dpl/ctx/test.rb', line 175 def tmp_dir FileUtils.mkdir_p('tmp') 'tmp' end |
#tty? ⇒ Boolean
240 241 242 |
# File 'lib/dpl/ctx/test.rb', line 240 def tty? false end |
#unmove_files(paths) ⇒ Object
207 208 209 210 211 |
# File 'lib/dpl/ctx/test.rb', line 207 def unmove_files(paths) paths.each do |path| mv("/tmp/#{File.basename(path)}", path) end end |
#validate_runtimes(runtimes) ⇒ Object
24 25 26 27 28 |
# File 'lib/dpl/ctx/test.rb', line 24 def validate_runtimes(runtimes) runtimes.each do |name, requirements| cmds << "[validate:runtime] #{name} (#{requirements.join(', ')})" end end |
#warn(msg) ⇒ Object
82 83 84 |
# File 'lib/dpl/ctx/test.rb', line 82 def warn(msg) cmds << "[warn] #{msg}" end |
#which(cmd) ⇒ Object
171 172 173 |
# File 'lib/dpl/ctx/test.rb', line 171 def which(cmd) false end |
#write_file(path, content, chmod = nil) ⇒ Object
225 226 227 228 229 230 |
# File 'lib/dpl/ctx/test.rb', line 225 def write_file(path, content, chmod = nil) path = File.(path) path = path.sub("#{File.('~')}", './home') FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w+') { |f| f.write(content) } end |
#write_netrc(machine, login, password) ⇒ Object
232 233 234 235 236 237 238 |
# File 'lib/dpl/ctx/test.rb', line 232 def write_netrc(machine, login, password) write_file('~/.netrc', sq(<<-rc)) machine #{machine} login #{login} password #{password} rc end |