MCPcopy
hub / github.com/purpleidea/mgmt / TestUserCheckApply_ModifyShell

Function TestUserCheckApply_ModifyShell

engine/resources/user_test.go:346–373  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

344}
345
346func TestUserCheckApply_ModifyShell(t *testing.T) {
347 f := &fakeUserFuncs{}
348 f.addUser(newTestUser("james", 1000, 1000, "/home/james/"), nil, "/bin/bash")
349 f.addGroup(&user.Group{Gid: "1000", Name: "james"})
350 f.install(t)
351
352 res := &UserRes{State: "exists", Shell: strPtr("/bin/msh")}
353 res.SetName("james")
354 res.SetKind("user")
355 if err := res.Init(fakeUserInit(t)); err != nil {
356 t.Fatal(err)
357 }
358
359 checkOK, err := res.CheckApply(context.Background(), true)
360 if err != nil {
361 t.Fatalf("func CheckApply: %v", err)
362 }
363 if checkOK {
364 t.Errorf("expected checkOK=false (shell differs)")
365 }
366 if len(f.cmds) != 1 || f.cmds[0].Name != "usermod" {
367 t.Fatalf("expected one usermod, got %v", f.cmds)
368 }
369 want := []string{"--shell", "/bin/msh", "james"}
370 if !reflect.DeepEqual(f.cmds[0].Args, want) {
371 t.Errorf("args mismatch:\n got: %v\nwant: %v", f.cmds[0].Args, want)
372 }
373}
374
375func TestUserCheckApply_Delete(t *testing.T) {
376 f := &fakeUserFuncs{}

Callers

nothing calls this directly

Calls 11

addUserMethod · 0.95
addGroupMethod · 0.95
installMethod · 0.95
InitMethod · 0.95
CheckApplyMethod · 0.95
newTestUserFunction · 0.85
strPtrFunction · 0.85
fakeUserInitFunction · 0.85
SetNameMethod · 0.65
SetKindMethod · 0.65
BackgroundMethod · 0.65

Tested by

no test coverage detected