This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
forked from bots-house/ghcr-delete-image-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.js
161 lines (142 loc) · 3.67 KB
/
utils.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const utils = require("./utils");
const github = require("@actions/github");
let withEnv = (envs, cb) => {
for (const k in envs) {
process.env[k] = envs[k];
}
cb();
for (const k in envs) {
delete process.env[k];
}
};
describe("getConfig", () => {
test("throw error if value is missing", () => {
expect(() => {
utils.getConfig();
}).toThrow();
});
const sharedRequiredOpts = {
INPUT_OWNER: "bots-house",
INPUT_NAME: "ghcr-delete-image-action",
INPUT_TOKEN: "some-token",
};
test("returns valid config", () => {
withEnv(
{
...sharedRequiredOpts,
INPUT_TAG: "latest",
},
() => {
expect(utils.getConfig()).toStrictEqual({
owner: "bots-house",
name: "ghcr-delete-image-action",
token: "some-token",
tag: "latest",
untaggedKeepLatest: null,
untaggedOlderThan: null,
});
}
);
});
test("throw error if no any required defined", () => {
withEnv(
{
...sharedRequiredOpts,
},
() => {
expect(() => utils.getConfig()).toThrow(
"no any required options defined"
);
}
);
});
test("throw error if more then on selector defined", () => {
withEnv(
{
...sharedRequiredOpts,
"INPUT_UNTAGGED-KEEP-LATEST": "2",
"INPUT_UNTAGGED-OLDER-THAN": "3",
},
() => {
expect(() => utils.getConfig()).toThrow(
"too many selectors defined, use only one"
);
}
);
});
test("throw error if untagged keep latest is not number", () => {
withEnv(
{
...sharedRequiredOpts,
"INPUT_UNTAGGED-KEEP-LATEST": "asdf",
},
() => {
expect(() => utils.getConfig()).toThrow(
"untagged-keep-latest is not number"
);
}
);
});
test("throw error if untagged older than is not number", () => {
withEnv(
{
...sharedRequiredOpts,
"INPUT_UNTAGGED-OLDER-THAN": "asdf",
},
() => {
expect(() => utils.getConfig()).toThrow(
"untagged-older-than is not number"
);
}
);
});
});
describe("findPackageVersionByTag", () => {
const token = process.env["INTEGRATION_TEST_TOKEN"];
expect(token).toBeTruthy();
const octokit = github.getOctokit(token);
test("existing version returns object", async () => {
const packageVersion = await utils.findPackageVersionByTag(
octokit,
"bots-house",
"docker-telegram-bot-api",
"fbb8b4c-b21d667"
);
expect(packageVersion.id).toBe(266441);
}, 15000);
test("not existing version throw error", () => {
return expect(
utils.findPackageVersionByTag(
octokit,
"bots-house",
"docker-telegram-bot-api",
"test"
)
).rejects.toThrow(new RegExp("package with tag"));
});
});
describe("findPackageVersionsUntaggedOrderGreaterThan", () => {
const token = process.env["INTEGRATION_TEST_TOKEN"];
expect(token).toBeTruthy();
const octokit = github.getOctokit(token);
test("returns greater than 5 objects", async () => {
const pkgs = await utils.findPackageVersionsUntaggedOrderGreaterThan(
octokit,
"bots-house",
"docker-telegram-bot-api",
2
);
expect(pkgs.length).toBeGreaterThanOrEqual(5);
// expect(packageVersion.id).toBe(266441);
}, 15000);
// test("not existing version throw error", () => {
// return expect(
// utils.findPackageVersionByTag(
// octokit,
// "bots-house",
// "docker-telegram-bot-api",
// "test"
// )
// ).rejects.toThrow(new RegExp("package with tag"));
// });
});