Sha256: f051e5e7a06a2b2dd554c0dd2600d98d0c9b3fbcbe6c5b19ffb1918f744651df

Contents?: true

Size: 766 Bytes

Versions: 52

Compression:

Stored size: 766 Bytes

Contents

module Unix::User
  include Beaker::CommandFactory

  def user_list(&block)
    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, &block)
    execute("getent passwd #{name}") do |result|
      fail_test "failed to get user #{name}" unless result.stdout =~  /^#{name}:/

      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

52 entries across 52 versions & 1 rubygems

Version Path
beaker-4.11.0 lib/beaker/host/unix/user.rb
beaker-4.10.0 lib/beaker/host/unix/user.rb
beaker-4.9.0 lib/beaker/host/unix/user.rb
beaker-4.8.0 lib/beaker/host/unix/user.rb
beaker-4.7.0 lib/beaker/host/unix/user.rb
beaker-4.6.0 lib/beaker/host/unix/user.rb
beaker-4.5.0 lib/beaker/host/unix/user.rb
beaker-4.4.0 lib/beaker/host/unix/user.rb
beaker-4.3.0 lib/beaker/host/unix/user.rb
beaker-4.2.0 lib/beaker/host/unix/user.rb
beaker-4.1.0 lib/beaker/host/unix/user.rb
beaker-4.0.0 lib/beaker/host/unix/user.rb