Skip to content

Commit bf01208

Browse files
committed
Fix tests
New inpsect functionality makes tests much more straight forward
1 parent 4ac02b5 commit bf01208

File tree

1 file changed

+14
-99
lines changed

1 file changed

+14
-99
lines changed

packages/testcontainers/src/generic-container/inspect-container-util-ports-exposed.test.ts

Lines changed: 14 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -71,108 +71,23 @@ describe.sequential("inspectContainerUntilPortsExposed", () => {
7171
"Timed out after 0ms while waiting for container ports to be bound to the host"
7272
);
7373
});
74-
});
75-
76-
test("correctly handles protocol parameter when specified as string", async () => {
77-
const data = mockInspectResult({ "8080/udp": [{ HostIp: "0.0.0.0", HostPort: "45000" }] });
78-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
79-
80-
const result = await inspectContainerUntilPortsExposed(inspectFn, ["8080/udp"], "container-id");
81-
82-
expect(result).toEqual(data);
83-
});
84-
85-
test("correctly handles protocol parameter when specified in object format", async () => {
86-
const data = mockInspectResult({ "8080/udp": [{ HostIp: "0.0.0.0", HostPort: "45000" }] });
87-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
88-
89-
const result = await inspectContainerUntilPortsExposed(
90-
inspectFn,
91-
[{ container: 8080, host: 45000, protocol: "udp" }],
92-
"container-id"
93-
);
94-
95-
expect(result).toEqual(data);
96-
});
97-
98-
test("uses tcp as default protocol when not specified", async () => {
99-
const data = mockInspectResult({ "8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }] });
100-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
101-
102-
const result = await inspectContainerUntilPortsExposed(inspectFn, [8080], "container-id");
103-
104-
expect(result).toEqual(data);
105-
});
106-
107-
test("handles multiple ports with different protocols", async () => {
108-
const ports = {
109-
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
110-
"9090/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
111-
};
112-
const data = mockInspectResult(ports);
113-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
114-
115-
const result = await inspectContainerUntilPortsExposed(inspectFn, [8080, "9090/udp"], "container-id");
11674

117-
expect(result).toEqual(data);
118-
});
119-
120-
test("fails when protocol doesn't match exposed port", async () => {
121-
const data = mockInspectResult({ "8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }] });
122-
const inspectFn = vi.fn().mockResolvedValue(data.inspectResult);
123-
124-
await expect(inspectContainerUntilPortsExposed(inspectFn, ["8080/udp"], "container-id", 0)).rejects.toThrow(
125-
"Container did not expose all ports after starting"
126-
);
127-
});
128-
129-
test("ignores ports with wrong protocol", async () => {
130-
const ports = {
131-
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
132-
"8080/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
133-
};
134-
const data = mockInspectResult(ports);
135-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
136-
137-
const result = await inspectContainerUntilPortsExposed(inspectFn, ["8080/udp"], "container-id");
75+
test("handles multiple ports with different protocols", async () => {
76+
const data = mockInspectResult(
77+
{
78+
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
79+
"9090/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
80+
},
81+
{
82+
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
83+
"9090/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
84+
}
85+
);
13886

139-
expect(result).toEqual(data);
140-
});
87+
const inspectFn = vi.fn().mockResolvedValueOnce(data);
14188

142-
test("handles mixed protocol specifications in different formats", async () => {
143-
const ports = {
144-
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
145-
"9090/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
146-
"7070/tcp": [{ HostIp: "0.0.0.0", HostPort: "47000" }],
147-
};
148-
const data = mockInspectResult(ports);
149-
const inspectFn = vi.fn().mockResolvedValueOnce(data.inspectResult);
150-
151-
const result = await inspectContainerUntilPortsExposed(
152-
inspectFn,
153-
[8080, "9090/udp", { container: 7070, host: 47000 }],
154-
"container-id"
155-
);
156-
157-
expect(result).toEqual(data);
158-
});
89+
const result = await inspectContainerUntilPortsExposed(inspectFn, "container-id");
15990

160-
test("retry with gradually exposed ports of different protocols", async () => {
161-
const data1 = mockInspectResult({});
162-
const data2 = mockInspectResult({ "8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }] });
163-
const data3 = mockInspectResult({
164-
"8080/tcp": [{ HostIp: "0.0.0.0", HostPort: "45000" }],
165-
"8080/udp": [{ HostIp: "0.0.0.0", HostPort: "46000" }],
91+
expect(result).toEqual(data);
16692
});
167-
168-
const inspectFn = vi
169-
.fn()
170-
.mockResolvedValueOnce(data1.inspectResult)
171-
.mockResolvedValueOnce(data2.inspectResult)
172-
.mockResolvedValueOnce(data3.inspectResult);
173-
174-
const result = await inspectContainerUntilPortsExposed(inspectFn, [8080, "8080/udp"], "container-id");
175-
176-
expect(result).toEqual(data3);
177-
expect(inspectFn).toHaveBeenCalledTimes(3);
17893
});

0 commit comments

Comments
 (0)