Sha256: 89b6e6784ad498ba3d3b1de0c68dd22eddd00387593ddf039662bf70747995b6

Contents?: true

Size: 753 Bytes

Versions: 16

Compression:

Stored size: 753 Bytes

Contents

module Unix::User
  include Beaker::CommandFactory

  def user_list
    execute("getent passwd") do |result|
      users = []
      result.stdout.each_line do |line|
        users << (line.match(/^([^:]+)/) or next)[1]
      end

      yield result if block_given?

      users
    end
  end

  def user_get(name)
    execute("getent passwd #{name}") do |result|
      fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)

      yield result if block_given?
      result
    end
  end

  def user_present(name, &block)
    execute("if ! getent passwd #{name}; then useradd #{name}; fi", {}, &block)
  end

  def user_absent(name, &block)
    execute("if getent passwd #{name}; then userdel #{name}; fi", {}, &block)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
beaker-6.4.1 lib/beaker/host/unix/user.rb
beaker-6.4.0 lib/beaker/host/unix/user.rb
beaker-6.3.0 lib/beaker/host/unix/user.rb
beaker-6.2.0 lib/beaker/host/unix/user.rb
beaker-6.1.0 lib/beaker/host/unix/user.rb
beaker-5.8.1 lib/beaker/host/unix/user.rb
beaker-5.8.0 lib/beaker/host/unix/user.rb
beaker-5.7.0 lib/beaker/host/unix/user.rb
beaker-5.6.0 lib/beaker/host/unix/user.rb
beaker-5.5.0 lib/beaker/host/unix/user.rb
beaker-5.4.0 lib/beaker/host/unix/user.rb
beaker-5.3.1 lib/beaker/host/unix/user.rb
beaker-5.3.0 lib/beaker/host/unix/user.rb
beaker-5.2.0 lib/beaker/host/unix/user.rb
beaker-5.1.0 lib/beaker/host/unix/user.rb
beaker-5.0.0 lib/beaker/host/unix/user.rb