Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
docker
/
metadata-action
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Security
Insights
Files
ef7eee9
.github
__mocks__
__tests__
fixtures
context.test.ts
flavor.test.ts
image.test.ts
meta.test.ts
tag.test.ts
dist
src
test
.dockerignore
.editorconfig
.eslintrc.json
.gitattributes
.gitignore
.prettierrc.json
LICENSE
README.md
UPGRADE.md
action.yml
codecov.yml
dev.Dockerfile
docker-bake.hcl
jest.config.ts
package.json
tsconfig.json
yarn.lock
Breadcrumbs
metadata-action
/
__tests__
/
context.test.ts
Blame
Blame
Latest commit
History
History
134 lines (125 loc) · 3.63 KB
Breadcrumbs
metadata-action
/
__tests__
/
context.test.ts
Top
File metadata and controls
Code
Blame
134 lines (125 loc) · 3.63 KB
Raw
import {afterEach, beforeEach, describe, expect, test, it, jest} from '@jest/globals'; import * as dotenv from 'dotenv'; import * as fs from 'fs'; import * as path from 'path'; import {Context} from '@actions/github/lib/context'; import {Git} from '@docker/actions-toolkit/lib/git'; import {GitHub} from '@docker/actions-toolkit/lib/github'; import {ContextSource, getContext, getInputs, Inputs} from '../src/context'; beforeEach(() => { jest.clearAllMocks(); jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => { return new Context(); }); }); describe('getInputs', () => { beforeEach(() => { process.env = Object.keys(process.env).reduce((object, key) => { if (!key.startsWith('INPUT_')) { object[key] = process.env[key]; } return object; }, {}); }); // prettier-ignore test.each([ [ 0, new Map<string, string>([ ['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'], ]), { context: ContextSource.workflow, bakeTarget: 'docker-metadata-action', flavor: [], githubToken: '', images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'], labels: [], sepLabels: '\n', sepTags: '\n', tags: [], } as Inputs ], [ 1, new Map<string, string>([ ['bake-target', 'metadata'], ['images', 'moby/buildkit'], ['sep-labels', ','], ['sep-tags', ','], ]), { context: ContextSource.workflow, bakeTarget: 'metadata', flavor: [], githubToken: '', images: ['moby/buildkit'], labels: [], sepLabels: ',', sepTags: ',', tags: [], } as Inputs ], [ 2, new Map<string, string>([ ['images', 'moby/buildkit\n#comment\nghcr.io/moby/mbuildkit'], ]), { context: ContextSource.workflow, bakeTarget: 'docker-metadata-action', flavor: [], githubToken: '', images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'], labels: [], sepLabels: '\n', sepTags: '\n', tags: [], } as Inputs ], ])( '[%d] given %p as inputs, returns %p', async (num: number, inputs: Map<string, string>, expected: Inputs) => { inputs.forEach((value: string, name: string) => { setInput(name, value); }); expect(await getInputs()).toEqual(expected); } ); }); describe('getContext', () => { const originalEnv = process.env; beforeEach(() => { jest.resetModules(); process.env = { ...originalEnv, ...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env'))) }; }); afterEach(() => { process.env = originalEnv; }); it('workflow', async () => { const context = await getContext(ContextSource.workflow); expect(context.ref).toEqual('refs/heads/dev'); expect(context.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a'); }); it('git', async () => { jest.spyOn(Git, 'context').mockImplementation((): Promise<Context> => { return Promise.resolve({ ref: 'refs/heads/git-test', sha: 'git-test-sha' } as Context); }); const context = await getContext(ContextSource.git); expect(context.ref).toEqual('refs/heads/git-test'); expect(context.sha).toEqual('git-test-sha'); }); }); // See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67 function getInputName(name: string): string { return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; } function setInput(name: string, value: string): void { process.env[getInputName(name)] = value; }
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
You can’t perform that action at this time.