|
1 | 1 | import { |
2 | | - isValidDockerImageReference, |
3 | 2 | RESPONSE_SIZE_LIMITS, |
4 | 3 | truncateAdditionalFacts, |
5 | 4 | } from "../../lib/utils"; |
6 | 5 |
|
7 | | -describe("isValidDockerImageReference", () => { |
8 | | - describe("valid image references", () => { |
9 | | - const validImages = [ |
10 | | - "nginx", |
11 | | - "ubuntu", |
12 | | - "alpine", |
13 | | - "nginx:latest", |
14 | | - "ubuntu:20.04", |
15 | | - "alpine:3.14", |
16 | | - "library/nginx", |
17 | | - "library/ubuntu:20.04", |
18 | | - "docker.io/nginx", |
19 | | - "docker.io/library/nginx:latest", |
20 | | - "gcr.io/project-id/image-name", |
21 | | - "gcr.io/project-id/image-name:tag", |
22 | | - "registry.hub.docker.com/library/nginx", |
23 | | - "localhost:5000/myimage", |
24 | | - "localhost:5000/myimage:latest", |
25 | | - "registry.example.com/path/to/image", |
26 | | - "registry.example.com:8080/path/to/image:v1.0", |
27 | | - "my-registry.com/my-namespace/my-image", |
28 | | - "my-registry.com/my-namespace/my-image:v2.1.0", |
29 | | - "nginx@sha256:abcd1234567890abcd1234567890abcd1234567890abcd1234567890abcd1234", |
30 | | - "ubuntu:20.04@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12", |
31 | | - "image_name", |
32 | | - "image.name", |
33 | | - "image-name", |
34 | | - "namespace/image_name.with-dots", |
35 | | - "registry.com/namespace/image__double_underscore", |
36 | | - "127.0.0.1:5000/test", |
37 | | - "[::1]:5000/test", |
38 | | - "registry.com/a/b/c/d/e/f/image", |
39 | | - "a.b.c/namespace/image:tag", |
40 | | - ]; |
41 | | - |
42 | | - it.each(validImages)( |
43 | | - "should return true for valid image reference: %s", |
44 | | - (imageName) => { |
45 | | - expect(isValidDockerImageReference(imageName)).toBe(true); |
46 | | - }, |
47 | | - ); |
48 | | - }); |
49 | | - |
50 | | - describe("invalid image references", () => { |
51 | | - const invalidImages = [ |
52 | | - "/test:unknown", |
53 | | - "//invalid", |
54 | | - "invalid//path", |
55 | | - "UPPERCASE", |
56 | | - "Invalid:Tag", |
57 | | - "registry.com/UPPERCASE/image", |
58 | | - "registry.com/namespace/UPPERCASE", |
59 | | - "", |
60 | | - "image:", |
61 | | - ":tag", |
62 | | - "image::", |
63 | | - "registry.com:", |
64 | | - "registry.com:/image", |
65 | | - "image@", |
66 | | - "image@sha256:", |
67 | | - "image@invalid:digest", |
68 | | - "registry.com//namespace/image", |
69 | | - "registry.com/namespace//image", |
70 | | - ".image", |
71 | | - "image.", |
72 | | - "-image", |
73 | | - "image-", |
74 | | - "_image", |
75 | | - "image_", |
76 | | - "registry-.com/image", |
77 | | - "registry.com-/image", |
78 | | - "image:tag@", |
79 | | - "image:tag@sha256", |
80 | | - "registry.com:abc/image", |
81 | | - "registry.com:-1/image", |
82 | | - ]; |
83 | | - |
84 | | - it.each(invalidImages)( |
85 | | - "should return false for invalid image reference: %s", |
86 | | - (imageName) => { |
87 | | - expect(isValidDockerImageReference(imageName)).toBe(false); |
88 | | - }, |
89 | | - ); |
90 | | - }); |
91 | | -}); |
92 | | - |
93 | 6 | describe("truncateAdditionalFacts", () => { |
94 | 7 | describe("should handle edge cases", () => { |
95 | 8 | it("should return empty array for empty input", () => { |
|
0 commit comments