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.
14 15 16 17 18 19 |
# File 'lib/dpl/ctx/test.rb', line 14 def initialize @cmds = [] @stderr = StringIO.new @stdout = {} super('dpl') end |
Instance Attribute Details
#cmds ⇒ Object (readonly)
Returns the value of attribute cmds.
12 13 14 |
# File 'lib/dpl/ctx/test.rb', line 12 def cmds @cmds end |
#last_err ⇒ Object (readonly)
Returns the value of attribute last_err.
12 13 14 |
# File 'lib/dpl/ctx/test.rb', line 12 def last_err @last_err end |
#last_out ⇒ Object (readonly)
Returns the value of attribute last_out.
12 13 14 |
# File 'lib/dpl/ctx/test.rb', line 12 def last_out @last_out end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
12 13 14 |
# File 'lib/dpl/ctx/test.rb', line 12 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
12 13 14 |
# File 'lib/dpl/ctx/test.rb', line 12 def stdout @stdout end |
Instance Method Details
#apt_get(name, cmd = name) ⇒ Object
36 37 38 |
# File 'lib/dpl/ctx/test.rb', line 36 def apt_get(name, cmd = name) cmds << "[apt:get] #{name} (#{cmd})" end |
#apts_get(apts) ⇒ Object
32 33 34 |
# File 'lib/dpl/ctx/test.rb', line 32 def apts_get(apts) apts.each { |apt| apt_get(*apt) } end |
#build_dir ⇒ Object
110 111 112 |
# File 'lib/dpl/ctx/test.rb', line 110 def build_dir '.' end |
#build_number ⇒ Object
114 115 116 |
# File 'lib/dpl/ctx/test.rb', line 114 def build_number 1 end |
#chmod(perm, path) ⇒ Object
227 228 229 |
# File 'lib/dpl/ctx/test.rb', line 227 def chmod(perm, path) cmds << [:chmod, perm, path].join(' ') end |
#deprecate_opt(key, msg) ⇒ Object
97 98 99 100 |
# File 'lib/dpl/ctx/test.rb', line 97 def deprecate_opt(key, msg) msg = "please use #{msg}" if msg.is_a?(Symbol) warn "Deprecated option #{key} used (#{msg})." end |
#encoding(_path) ⇒ Object
189 190 191 |
# File 'lib/dpl/ctx/test.rb', line 189 def encoding(_path) 'text' end |
#error(message) ⇒ Object
93 94 95 |
# File 'lib/dpl/ctx/test.rb', line 93 def error() raise Error, end |
#except(hash, *keys) ⇒ Object
250 251 252 |
# File 'lib/dpl/ctx/test.rb', line 250 def except(hash, *keys) hash.reject { |key, _| keys.include?(key) } end |
#file_size(path) ⇒ Object
203 204 205 |
# File 'lib/dpl/ctx/test.rb', line 203 def file_size(path) File.size(path.sub(File.('~').to_s, './home')) end |
#fold(name) ⇒ Object
21 22 23 24 |
# File 'lib/dpl/ctx/test.rb', line 21 def fold(name) cmds << "[fold] #{name}" yield.tap { cmds << "[unfold] #{name}" } end |
#gem_require(name, version = nil, opts = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dpl/ctx/test.rb', line 44 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 begin require opts[:require] || name rescue StandardError nil end cmds << "[gem:require] #{name} (#{version}, #{opts})" end |
#gems_require(gems) ⇒ Object
40 41 42 |
# File 'lib/dpl/ctx/test.rb', line 40 def gems_require(gems) gems.each { |gem| gem_require(*gem) } end |
#git_author_email ⇒ Object
130 131 132 |
# File 'lib/dpl/ctx/test.rb', line 130 def 'author email' end |
#git_author_name ⇒ Object
126 127 128 |
# File 'lib/dpl/ctx/test.rb', line 126 def 'author name' end |
#git_branch ⇒ Object
118 119 120 |
# File 'lib/dpl/ctx/test.rb', line 118 def git_branch 'git branch' end |
#git_commit_msg ⇒ Object
122 123 124 |
# File 'lib/dpl/ctx/test.rb', line 122 def git_commit_msg 'commit msg' end |
#git_dirty? ⇒ Boolean
134 135 136 |
# File 'lib/dpl/ctx/test.rb', line 134 def git_dirty? true end |
#git_log(_args) ⇒ Object
138 139 140 |
# File 'lib/dpl/ctx/test.rb', line 138 def git_log(_args) 'commits' end |
#git_ls_files ⇒ Object
142 143 144 |
# File 'lib/dpl/ctx/test.rb', line 142 def git_ls_files %w[one two] end |
#git_ls_remote?(_url, _ref) ⇒ Boolean
146 147 148 |
# File 'lib/dpl/ctx/test.rb', line 146 def git_ls_remote?(_url, _ref) true end |
#git_remote_urls ⇒ Object
150 151 152 |
# File 'lib/dpl/ctx/test.rb', line 150 def git_remote_urls ['git://origin.git'] end |
#git_rev_parse(ref) ⇒ Object
154 155 156 |
# File 'lib/dpl/ctx/test.rb', line 154 def git_rev_parse(ref) "ref: #{ref}" end |
#git_sha ⇒ Object
162 163 164 |
# File 'lib/dpl/ctx/test.rb', line 162 def git_sha 'sha' end |
#git_tag ⇒ Object
158 159 160 |
# File 'lib/dpl/ctx/test.rb', line 158 def git_tag 'tag' end |
#info(msg) ⇒ Object
81 82 83 |
# File 'lib/dpl/ctx/test.rb', line 81 def info(msg) cmds << "[info] #{msg}" end |
#logger(level = :info) ⇒ Object
193 194 195 196 197 |
# File 'lib/dpl/ctx/test.rb', line 193 def logger(level = :info) logger = Logger.new(stderr) logger.level = Logger.const_get(level.to_s.upcase) logger end |
#machine_name ⇒ Object
166 167 168 |
# File 'lib/dpl/ctx/test.rb', line 166 def machine_name 'machine_name' end |
#move_files(paths) ⇒ Object
207 208 209 210 211 |
# File 'lib/dpl/ctx/test.rb', line 207 def move_files(paths) paths.each do |path| mv(path, "/tmp/#{File.basename(path)}") end end |
#mv(src, dest) ⇒ Object
219 220 221 |
# File 'lib/dpl/ctx/test.rb', line 219 def mv(src, dest) cmds << [:mv, src, dest].join(' ') end |
#node_version ⇒ Object
170 171 172 |
# File 'lib/dpl/ctx/test.rb', line 170 def node_version '11.0.0' end |
#npm_install(name, cmd = name) ⇒ Object
55 56 57 |
# File 'lib/dpl/ctx/test.rb', line 55 def npm_install(name, cmd = name) cmds << "[npm:install] #{name} (#{cmd})" end |
#npm_version ⇒ Object
174 175 176 |
# File 'lib/dpl/ctx/test.rb', line 174 def npm_version '1' end |
#pip_install(name, cmd = name, version = nil) ⇒ Object
59 60 61 |
# File 'lib/dpl/ctx/test.rb', line 59 def pip_install(name, cmd = name, version = nil) cmds << "[pip:install] #{name} (#{cmd}, #{version})" end |
#print(chars) ⇒ Object
85 86 87 |
# File 'lib/dpl/ctx/test.rb', line 85 def print(chars) cmds << "[print] #{chars}" end |
#repo_name ⇒ Object
102 103 104 |
# File 'lib/dpl/ctx/test.rb', line 102 def repo_name 'dpl' end |
#repo_slug ⇒ Object
106 107 108 |
# File 'lib/dpl/ctx/test.rb', line 106 def repo_slug 'travis-ci/dpl' end |
#rm_rf(path) ⇒ Object
223 224 225 |
# File 'lib/dpl/ctx/test.rb', line 223 def rm_rf(path) cmds << [:rm_rf, path].join(' ') end |
#shell(cmd, _opts = {}) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/dpl/ctx/test.rb', line 68 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
187 |
# File 'lib/dpl/ctx/test.rb', line 187 def sleep(*); end |
#ssh_keygen(_name, file) ⇒ Object
63 64 65 66 |
# File 'lib/dpl/ctx/test.rb', line 63 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
77 78 79 |
# File 'lib/dpl/ctx/test.rb', line 77 def success? true end |
#test? ⇒ Boolean
199 200 201 |
# File 'lib/dpl/ctx/test.rb', line 199 def test? true end |
#tmp_dir ⇒ Object
182 183 184 185 |
# File 'lib/dpl/ctx/test.rb', line 182 def tmp_dir FileUtils.mkdir_p('tmp') 'tmp' end |
#tty? ⇒ Boolean
246 247 248 |
# File 'lib/dpl/ctx/test.rb', line 246 def tty? false end |
#unmove_files(paths) ⇒ Object
213 214 215 216 217 |
# File 'lib/dpl/ctx/test.rb', line 213 def unmove_files(paths) paths.each do |path| mv("/tmp/#{File.basename(path)}", path) end end |
#validate_runtimes(runtimes) ⇒ Object
26 27 28 29 30 |
# File 'lib/dpl/ctx/test.rb', line 26 def validate_runtimes(runtimes) runtimes.each do |name, requirements| cmds << "[validate:runtime] #{name} (#{requirements.join(', ')})" end end |
#warn(msg) ⇒ Object
89 90 91 |
# File 'lib/dpl/ctx/test.rb', line 89 def warn(msg) cmds << "[warn] #{msg}" end |
#which(_cmd) ⇒ Object
178 179 180 |
# File 'lib/dpl/ctx/test.rb', line 178 def which(_cmd) false end |
#write_file(path, content, _chmod = nil) ⇒ Object
231 232 233 234 235 236 |
# File 'lib/dpl/ctx/test.rb', line 231 def write_file(path, content, _chmod = nil) path = File.(path) path = path.sub(File.('~').to_s, './home') FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w+') { |f| f.write(content) } end |
#write_netrc(machine, login, password) ⇒ Object
238 239 240 241 242 243 244 |
# File 'lib/dpl/ctx/test.rb', line 238 def write_netrc(machine, login, password) write_file('~/.netrc', sq(<<-RC)) machine #{machine} login #{login} password #{password} RC end |