TestUserCheckApply_Issue842 reproduces github.com/purpleidea/mgmt/issues/842 mcl `user "mgmttest" { state => "exists" }` with no other fields, where the user already exists. The user has a primary group (mgmttest) and one supplemental group it is naturally a member of. Without the primary-GID skip
(t *testing.T)
| 460 | // mismatch and the apply branch runs `usermod LOGIN` with no other args, |
| 461 | // producing "usermod: no options". This test pins the no-op behavior. |
| 462 | func TestUserCheckApply_Issue842(t *testing.T) { |
| 463 | f := loadEtc(t, |
| 464 | "mgmttest:x:5000:5000::/home/mgmttest/:/bin/bash", |
| 465 | strings.Join([]string{ |
| 466 | "mgmttest:x:5000:", // primary group |
| 467 | "extras:x:6000:mgmttest", // supplemental |
| 468 | }, "\n"), |
| 469 | ) |
| 470 | f.install(t) |
| 471 | |
| 472 | // Resource asks for exactly the supplemental group the user already has. |
| 473 | res := mkUser("mgmttest", "exists", func(r *UserRes) { |
| 474 | r.Groups = []string{"extras"} |
| 475 | }) |
| 476 | if err := res.Init(fakeUserInit(t)); err != nil { |
| 477 | t.Fatal(err) |
| 478 | } |
| 479 | |
| 480 | checkOK, err := res.CheckApply(context.Background(), true) |
| 481 | if err != nil { |
| 482 | t.Fatalf("func CheckApply: unexpected error: %v", err) |
| 483 | } |
| 484 | if !checkOK { |
| 485 | t.Errorf("expected no-op (checkOK=true); got false") |
| 486 | } |
| 487 | if len(f.cmds) != 0 { |
| 488 | t.Errorf("expected no commands; got %v", f.cmds) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // TestUserCheckApply_EmptyGroupsClears asserts the semantic distinction between |
| 493 | // a nil Groups field and an empty-but-non-nil Groups field. nil means "do not |
nothing calls this directly
no test coverage detected