package mapping import ( "strings" "testing" ) // TestDeptGroupDN 验证部门组 DN 直接用部门稳定索引(dept_id),不编码祖先路径。 func TestDeptGroupDN(t *testing.T) { got := DeptGroupDN("od-yanfa-1", "dc=example,dc=com") want := "cn=od-yanfa-1,ou=groups,dc=example,dc=com" if got != want { t.Errorf("DeptGroupDN = %q, 期望 %q", got, want) } } // TestDeptGroupDNStableAcrossRename 验证部门改名(中文名变化)不影响组 DN—— // 组身份绑在索引上,改名不引起身份漂移。 func TestDeptGroupDNStableAcrossRename(t *testing.T) { a := DeptGroupDN("od-123", "dc=example,dc=com") // 无论部门叫「研发部」还是「产品部」,索引不变,DN 不变。 b := DeptGroupDN("od-123", "dc=example,dc=com") if a != b { t.Errorf("同索引的组 DN 应稳定不变: %q vs %q", a, b) } } // TestDeptGroupDNDistinct 验证不同部门索引产生不同组 DN。 func TestDeptGroupDNDistinct(t *testing.T) { a := DeptGroupDN("od-1", "dc=example,dc=com") b := DeptGroupDN("od-2", "dc=example,dc=com") if a == b { t.Errorf("不同部门索引的组 DN 不应相同") } } // TestGroupRootDN 验证组根 OU 固定挂在 ou=groups 下。 func TestGroupRootDN(t *testing.T) { if got := GroupRootDN("dc=example,dc=com"); got != "ou=groups,dc=example,dc=com" { t.Errorf("GroupRootDN = %q", got) } if !strings.HasPrefix(DeptGroupDN("od-1", "dc=example,dc=com"), "cn=") { t.Errorf("组 DN 应以 cn= 开头") } }