Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4a61bcf

Browse files
committedMar 13, 2025·
HMS-5617: package groups test
1 parent ca22749 commit 4a61bcf

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { expectError, test } from './base_client';
2+
import {
3+
ApiRepositoryResponse,
4+
GetRepositoryRequest,
5+
type ListRepositoriesRequest,
6+
PackagegroupsApi,
7+
RepositoriesApi,
8+
} from './client';
9+
import { expect } from '@playwright/test';
10+
import { randomName } from './helpers/repoHelpers';
11+
import { poll } from './apiHelpers';
12+
import { randomUUID } from 'crypto';
13+
14+
test.describe('Package groups', () => {
15+
test('Search and list package groups', async ({ client }) => {
16+
const repoUrl = 'https://content-services.github.io/fixtures/yum/comps-modules/v1/';
17+
const repoName = randomName();
18+
let repoUuid: string | undefined;
19+
const expectedGroup = 'birds';
20+
const expectedPackageList = ['penguin', 'duck', 'cockateel', 'stork'];
21+
22+
await test.step('Delete existing repository if exists', async () => {
23+
const existing = await new RepositoriesApi(client).listRepositories(<ListRepositoriesRequest>{
24+
url: repoUrl,
25+
});
26+
27+
if (existing?.data?.length) {
28+
const resp = await new RepositoriesApi(client).deleteRepositoryRaw(<GetRepositoryRequest>{
29+
uuid: existing.data[0].uuid?.toString(),
30+
});
31+
expect(resp.raw.status).toBe(204);
32+
}
33+
});
34+
35+
await test.step('Create repo with package groups', async () => {
36+
const repo = await new RepositoriesApi(client).createRepository({
37+
apiRepositoryRequest: {
38+
name: repoName,
39+
url: repoUrl,
40+
},
41+
});
42+
43+
repoUuid = repo.uuid;
44+
expect(repo.name).toBe(repoName);
45+
expect(repo.url).toBe(repoUrl);
46+
});
47+
48+
await test.step('Wait for repo to be introspected', async () => {
49+
const waitWhilePending = (resp: ApiRepositoryResponse) => resp.status === 'Pending';
50+
const getRepository = () =>
51+
new RepositoriesApi(client).getRepository(<GetRepositoryRequest>{
52+
uuid: repoUuid,
53+
});
54+
const resp = await poll(getRepository, waitWhilePending, 10);
55+
expect(resp.status).toBe('Valid');
56+
});
57+
58+
await test.step('Partial search for package groups', async () => {
59+
const partialMatchesWithUrl = await new PackagegroupsApi(client).searchPackageGroup({
60+
apiContentUnitSearchRequest: { urls: [repoUrl], uuids: [], search: 'b' },
61+
});
62+
63+
const partialMatchesWithUuid = await new PackagegroupsApi(client).searchPackageGroup({
64+
apiContentUnitSearchRequest: { urls: [], uuids: [repoUuid!], search: 'b' },
65+
});
66+
67+
const noMatches = await new PackagegroupsApi(client).searchPackageGroup({
68+
apiContentUnitSearchRequest: { urls: [], uuids: [repoUuid!], search: 'x' },
69+
});
70+
71+
expect(partialMatchesWithUrl.length).toBe(1);
72+
expect(partialMatchesWithUrl[0].packageGroupName).toBe(expectedGroup);
73+
expect(partialMatchesWithUrl[0].packageList?.length).toBe(expectedPackageList.length);
74+
expect(partialMatchesWithUrl[0].packageList?.sort()).toStrictEqual(
75+
expectedPackageList.sort(),
76+
);
77+
expect(partialMatchesWithUuid.length).toBe(partialMatchesWithUrl.length);
78+
expect(partialMatchesWithUuid[0].packageGroupName).toBe(
79+
partialMatchesWithUrl[0].packageGroupName,
80+
);
81+
expect(partialMatchesWithUuid[0].packageList?.length).toBe(
82+
partialMatchesWithUrl[0].packageList?.length,
83+
);
84+
expect(partialMatchesWithUuid[0].packageList?.sort()).toStrictEqual(
85+
partialMatchesWithUrl[0].packageList?.sort(),
86+
);
87+
expect(noMatches.length).toBe(0);
88+
});
89+
90+
await test.step('Exact search for package groups', async () => {
91+
const exactMatchesWithUrl = await new PackagegroupsApi(client).searchPackageGroup({
92+
apiContentUnitSearchRequest: { urls: [repoUrl], uuids: [], exactNames: [expectedGroup] },
93+
});
94+
95+
const exactMatchesWithUuid = await new PackagegroupsApi(client).searchPackageGroup({
96+
apiContentUnitSearchRequest: { urls: [], uuids: [repoUuid!], exactNames: [expectedGroup] },
97+
});
98+
99+
const noMatches = await new PackagegroupsApi(client).searchPackageGroup({
100+
apiContentUnitSearchRequest: { urls: [], uuids: [repoUuid!], exactNames: ['fake-group'] },
101+
});
102+
103+
expect(exactMatchesWithUrl.length).toBe(1);
104+
expect(exactMatchesWithUrl[0].packageGroupName).toBe(expectedGroup);
105+
expect(exactMatchesWithUrl[0].packageList?.length).toBe(expectedPackageList.length);
106+
expect(exactMatchesWithUrl[0].packageList?.sort()).toStrictEqual(expectedPackageList.sort());
107+
expect(exactMatchesWithUuid.length).toBe(exactMatchesWithUrl.length);
108+
expect(exactMatchesWithUuid[0].packageGroupName).toBe(
109+
exactMatchesWithUrl[0].packageGroupName,
110+
);
111+
expect(exactMatchesWithUuid[0].packageList?.length).toBe(
112+
exactMatchesWithUrl[0].packageList?.length,
113+
);
114+
expect(exactMatchesWithUuid[0].packageList?.sort()).toStrictEqual(
115+
exactMatchesWithUrl[0].packageList?.sort(),
116+
);
117+
expect(noMatches.length).toBe(0);
118+
});
119+
120+
await test.step('List package groups of a repo', async () => {
121+
const packageGroups = await new PackagegroupsApi(client).listRepositoriesPackageGroups({
122+
uuid: repoUuid!,
123+
});
124+
125+
expect(packageGroups?.data?.length).toBe(1);
126+
expect(packageGroups?.data?.[0].name).toBe(expectedGroup);
127+
expect(packageGroups?.data?.[0].packagelist?.sort()).toStrictEqual(
128+
expectedPackageList.sort(),
129+
);
130+
});
131+
132+
await test.step('Searching package groups with a repo url or uuid that does not exist results in 404', async () => {
133+
const invalidRepoUuid = randomUUID();
134+
const invalidRepoUrl = 'https://fake-repo.com';
135+
136+
await expectError(
137+
404,
138+
'Could not find repository with URL',
139+
new PackagegroupsApi(client).searchPackageGroup({
140+
apiContentUnitSearchRequest: {
141+
urls: [invalidRepoUrl],
142+
uuids: [],
143+
exactNames: [expectedGroup],
144+
},
145+
}),
146+
);
147+
148+
await expectError(
149+
404,
150+
'Could not find repository with UUID',
151+
new PackagegroupsApi(client).searchPackageGroup({
152+
apiContentUnitSearchRequest: {
153+
urls: [],
154+
uuids: [invalidRepoUuid],
155+
exactNames: [expectedGroup],
156+
},
157+
}),
158+
);
159+
});
160+
161+
await test.step('Listing package groups with a repo uuid that does not exist results in 404', async () => {
162+
const invalidRepoUuid = randomUUID();
163+
164+
await expectError(
165+
404,
166+
'Could not find repository with UUID',
167+
new PackagegroupsApi(client).listRepositoriesPackageGroups({
168+
uuid: invalidRepoUuid,
169+
}),
170+
);
171+
});
172+
173+
await test.step('Delete repository', async () => {
174+
const resp = await new RepositoriesApi(client).deleteRepositoryRaw(<GetRepositoryRequest>{
175+
uuid: repoUuid,
176+
});
177+
expect(resp.raw.status).toBe(204);
178+
});
179+
});
180+
});

0 commit comments

Comments
 (0)
Please sign in to comment.