1
Fork 0

test packed users iterator

This commit is contained in:
Motiejus Jakštys 2022-03-15 06:26:48 +02:00 committed by Motiejus Jakštys
parent 2c4e61d0ed
commit 6bf3e10eed
3 changed files with 19 additions and 12 deletions

View File

@ -377,7 +377,7 @@ Section creation order:
1. ✅ userGids. No dependencies.
1. ✅ Users. Requires `userGids` and shell.
1. ✅ Groupmembers. Requires Users.
1. Groups. Requires Groupmembers.
1. Groups. Requires Groupmembers.
1. `idx_*`. Requires offsets to Groups and Users.
1. Header.

View File

@ -563,7 +563,7 @@ test "test corpus" {
try testing.expectEqual(groupsOfVidmantas[2], g_all);
}
test "test groups and group members" {
test "test groups, group members and users" {
const allocator = testing.allocator;
var corpus = try testCorpus(allocator);
defer corpus.deinit();
@ -572,12 +572,12 @@ test "test groups and group members" {
defer sections.deinit();
const blob = sections.group_members.blob;
var group_idx: usize = 0;
while (group_idx < corpus.groups.len) : (group_idx += 1) {
const offset = sections.group_members.idx2offset[group_idx];
var i: usize = 0;
while (i < corpus.groups.len) : (i += 1) {
const offset = sections.group_members.idx2offset[i];
var vit = try compress.VarintSliceIterator(blob[offset..]);
var it = compress.DeltaDecompressionIterator(&vit);
for (corpus.group2users[group_idx]) |user_idx| {
for (corpus.group2users[i]) |user_idx| {
const got_user_offset = (try it.next()).?;
const want_user_offset = sections.users.idx2offset[user_idx];
try testing.expectEqual(got_user_offset, want_user_offset);
@ -589,7 +589,16 @@ test "test groups and group members" {
sections.users.blob,
sections.shell_reader,
);
_ = it;
i = 0;
while (i < corpus.users.len) : (i += 1) {
const user = (try it.next()).?;
try testing.expectEqual(corpus.users[i].uid, user.uid());
try testing.expectEqual(corpus.users[i].gid, user.gid());
try testing.expectEqualStrings(corpus.users[i].name, user.name());
try testing.expectEqualStrings(corpus.users[i].gecos, user.gecos());
try testing.expectEqualStrings(corpus.users[i].home, user.home());
try testing.expectEqualStrings(corpus.users[i].shell, user.shell(sections.shell_reader));
}
}
test "userGids" {

View File

@ -338,9 +338,10 @@ test "construct PackedUser section" {
.shell = "/",
} };
var shellIndex = testShellIndex(testing.allocator);
const additional_gids = math.maxInt(u64);
defer shellIndex.deinit();
for (users) |user| {
try PackedUser.packTo(&buf, user, math.maxInt(u64), shellIndex);
try PackedUser.packTo(&buf, user, additional_gids, shellIndex);
try pad.arrayList(&buf, PackedUser.alignment_bits);
}
@ -349,10 +350,7 @@ test "construct PackedUser section" {
while (try it1.next()) |user| : (i += 1) {
try testing.expectEqual(users[i].uid, user.uid());
try testing.expectEqual(users[i].gid, user.gid());
try testing.expectEqual(
@as(u64, math.maxInt(u64)),
user.additionalGidsOffset(),
);
try testing.expectEqual(user.additionalGidsOffset(), additional_gids);
try testing.expectEqualStrings(users[i].name, user.name());
try testing.expectEqualStrings(users[i].gecos, user.gecos());
try testing.expectEqualStrings(users[i].home, user.home());