1 require 'minitest/autorun'
5 class TestAddUser < Minitest::Test
9 # binstub_new_user/useradd will exit non-zero because its args
10 # won't match any line in this empty file:
11 File.open(@tmpdir+'/succeed', 'w') do |f| end
12 invoke_sync binstubs: ['new_user']
13 spied = File.read(@tmpdir+'/spy')
14 assert_match %r{useradd -m -c active -s /bin/bash -G fuse active}, spied
15 assert_match %r{useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot}, spied
18 def test_useradd_success
19 # binstub_new_user/useradd will exit non-zero because its args
20 # won't match any line in this empty file:
21 File.open(@tmpdir+'/succeed', 'w') do |f|
22 f.puts 'useradd -m -c active -s /bin/bash -G fuse active'
23 f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot'
25 $stderr.puts "*** Expect crash in dir_s_mkdir:"
26 invoke_sync binstubs: ['new_user']
28 spied = File.read(@tmpdir+'/spy')
29 # Expect a crash after adding one user, because Dir.mkdir({home}) fails.
30 assert_match %r{^useradd -m -c [^\n]+\n$}s, spied