@defra/grants-config-utils 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/check-pull-request.yml +6 -3
- package/.github/workflows/release.yml +5 -5
- package/.husky/pre-commit +16 -0
- package/CHANGELOG.md +9 -0
- package/README.md +10 -0
- package/package.json +1 -1
- package/src/service/config-store-and-inform.js +42 -8
- package/src/service/config-store-and-inform.test.js +182 -131
|
@@ -18,8 +18,11 @@ jobs:
|
|
|
18
18
|
name: Run Pull Request Checks
|
|
19
19
|
runs-on: ubuntu-latest
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@v6
|
|
22
|
-
|
|
21
|
+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
24
|
+
|
|
25
|
+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
|
|
23
26
|
with:
|
|
24
27
|
node-version-file: .nvmrc
|
|
25
28
|
registry-url: "https://registry.npmjs.org/"
|
|
@@ -43,7 +46,7 @@ jobs:
|
|
|
43
46
|
- name: SonarCloud Scan
|
|
44
47
|
if: github.actor != 'dependabot[bot]' &&
|
|
45
48
|
!startsWith(github.head_ref, 'changeset-release/')
|
|
46
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
49
|
+
uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 #8.1.0
|
|
47
50
|
env:
|
|
48
51
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
49
52
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -25,13 +25,13 @@ jobs:
|
|
|
25
25
|
|
|
26
26
|
steps:
|
|
27
27
|
- name: Checkout repository
|
|
28
|
-
uses: actions/checkout@v6
|
|
28
|
+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6
|
|
29
29
|
with:
|
|
30
30
|
fetch-depth: 0
|
|
31
31
|
fetch-tags: true
|
|
32
32
|
|
|
33
33
|
- name: Set up Node.js
|
|
34
|
-
uses: actions/setup-node@v6
|
|
34
|
+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
|
|
35
35
|
with:
|
|
36
36
|
node-version-file: .nvmrc
|
|
37
37
|
registry-url: "https://registry.npmjs.org/"
|
|
@@ -44,7 +44,7 @@ jobs:
|
|
|
44
44
|
|
|
45
45
|
- name: SonarCloud Scan
|
|
46
46
|
if: github.actor != 'dependabot[bot]' && github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, 'Create new config version')
|
|
47
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
47
|
+
uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 #8.1.0
|
|
48
48
|
env:
|
|
49
49
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
50
50
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -54,7 +54,7 @@ jobs:
|
|
|
54
54
|
|
|
55
55
|
- name: Create Release Pull Request or Release
|
|
56
56
|
id: changesets
|
|
57
|
-
uses: changesets/action@v1
|
|
57
|
+
uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d #v1.9.0
|
|
58
58
|
with:
|
|
59
59
|
commitMode: 'github-api'
|
|
60
60
|
publish: npm run github:release
|
|
@@ -63,7 +63,7 @@ jobs:
|
|
|
63
63
|
|
|
64
64
|
- name: Trigger required checks on release PR, then merge to main, and delete release branch
|
|
65
65
|
if: ${{ !startsWith(github.event_name == 'push' && github.event.head_commit.message || inputs.commit_message, 'Create new config version') }}
|
|
66
|
-
uses: actions/github-script@
|
|
66
|
+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9.0.0
|
|
67
67
|
with:
|
|
68
68
|
script: |
|
|
69
69
|
const prNumber = Number("${{ steps.changesets.outputs.pullRequestNumber }}");
|
package/.husky/pre-commit
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
npx lint-staged
|
|
2
|
+
|
|
3
|
+
branch="$(git symbolic-ref --short HEAD)"
|
|
4
|
+
currentUser="$(git config user.name)"
|
|
5
|
+
if [ "$currentUser" != "github-actions[bot]" ]; then
|
|
6
|
+
if [ "$branch" = "main" ]; then
|
|
7
|
+
echo "❌ Pushing to main is not allowed!"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
if git diff --name-only origin/HEAD...HEAD >/dev/null; then
|
|
11
|
+
if ! compgen -G ".changeset/*-*-*.md" > /dev/null; then
|
|
12
|
+
echo "❌ Make sure you have added a changeset file"
|
|
13
|
+
echo "Run: npm run version"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
fi
|
|
17
|
+
fi
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -24,6 +24,16 @@ The following variables are used in this module:
|
|
|
24
24
|
- `CONFIG_BUCKET_NAME` - **Required** The S3 bucket where the config is to be stored
|
|
25
25
|
- `FORCE_PATH_STYLE` - Optional flag to force path style URLs when using S3 bucket (default true)
|
|
26
26
|
- `AWS_ENDPOINT_URL` - Optional AWS endpoint URL for local development
|
|
27
|
+
- `GRANTS_CONFIG_PUBLISH_STATUS` - Optional override for status used on publish of config versions (default 'active')
|
|
28
|
+
|
|
29
|
+
Depending on which mechanism is used to publish config versions, the following environment variables may be required:
|
|
30
|
+
|
|
31
|
+
**To publish asynchronously via SNS (Recommended)**
|
|
32
|
+
|
|
33
|
+
- `GFR__SNS__CONFIG_VERSION_ARN` - **Required** ARN of the SNS topic to publish config version events to
|
|
34
|
+
|
|
35
|
+
**To publish synchronously via REST API**
|
|
36
|
+
|
|
27
37
|
- `GRANTS_CONFIG_BROKER_AUTH_TOKEN` - **Required** Auth token for the grants config broker API
|
|
28
38
|
- `GRANTS_CONFIG_BROKER_ENCRYPTION_KEY` - **Required** Encryption key for the grants config broker API
|
|
29
39
|
- `GRANTS_CONFIG_BROKER_API_ENDPOINT` - **Required** Endpoint for the grants config broker API
|
package/package.json
CHANGED
|
@@ -2,6 +2,11 @@ import { readFileSync, existsSync, lstatSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { config } from "../config/config.js";
|
|
3
3
|
import { listFiles, uploadBlob } from "../s3/s3-interactions.js";
|
|
4
4
|
import { createApiHeadersForConfigBroker } from "../broker/broker-auth-helper.js";
|
|
5
|
+
import {
|
|
6
|
+
isClientSetup,
|
|
7
|
+
publishMessage,
|
|
8
|
+
setupClient,
|
|
9
|
+
} from "../sns/sns-client.js";
|
|
5
10
|
|
|
6
11
|
const configsDirectory = "configurations";
|
|
7
12
|
|
|
@@ -101,11 +106,13 @@ const notifyConfigBrokerServiceVersionAvailable = async (
|
|
|
101
106
|
logger,
|
|
102
107
|
) => {
|
|
103
108
|
const configBrokerEndpoint = config.get("configBroker.apiEndpoint");
|
|
109
|
+
const configSNSTopic = config.get("aws.sns.configVersionTopicArn");
|
|
104
110
|
const configPublishStatus = config.get("configPublish.status");
|
|
105
111
|
|
|
106
112
|
// iterate each grant configuration, notify config available at current service version
|
|
107
113
|
for (const configAtServiceVersion of configsAtServiceVersion) {
|
|
108
114
|
await sendConfigMessageToBroker(
|
|
115
|
+
configSNSTopic,
|
|
109
116
|
configBrokerEndpoint,
|
|
110
117
|
configAtServiceVersion,
|
|
111
118
|
configPublishStatus,
|
|
@@ -115,19 +122,12 @@ const notifyConfigBrokerServiceVersionAvailable = async (
|
|
|
115
122
|
};
|
|
116
123
|
|
|
117
124
|
const sendConfigMessageToBroker = async (
|
|
125
|
+
configSNSTopic,
|
|
118
126
|
configBrokerEndpoint,
|
|
119
127
|
configAtServiceVersion,
|
|
120
128
|
configPublishStatus,
|
|
121
129
|
logger,
|
|
122
130
|
) => {
|
|
123
|
-
// TODO BH check service topic set instead
|
|
124
|
-
if (!configBrokerEndpoint?.length) {
|
|
125
|
-
logger.warn(
|
|
126
|
-
`config broker endpoint not set, so skipping release config call`,
|
|
127
|
-
);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
131
|
const { grant, version, files } = configAtServiceVersion;
|
|
132
132
|
// files is an array of tuples, we only want the S3 paths here
|
|
133
133
|
const s3Paths = files.map(([_, s3Path]) => s3Path);
|
|
@@ -139,6 +139,17 @@ const sendConfigMessageToBroker = async (
|
|
|
139
139
|
status: configPublishStatus,
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
+
if (setToUseSNS(configSNSTopic)) {
|
|
143
|
+
return sendViaSNS(payload, configSNSTopic, logger);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!configBrokerEndpoint?.length) {
|
|
147
|
+
logger.warn(
|
|
148
|
+
`config SNS topic not set, and config broker endpoint not set, so skipping release config call`,
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
142
153
|
const url = new URL(`/api/release-config`, configBrokerEndpoint);
|
|
143
154
|
try {
|
|
144
155
|
const response = await fetch(url.href, {
|
|
@@ -163,3 +174,26 @@ const sendConfigMessageToBroker = async (
|
|
|
163
174
|
logger.error("call to release config failed", err);
|
|
164
175
|
}
|
|
165
176
|
};
|
|
177
|
+
|
|
178
|
+
const sendViaSNS = async (payload, configSNSTopic, logger) => {
|
|
179
|
+
if (!isClientSetup()) {
|
|
180
|
+
setupClient(logger.child({}), {
|
|
181
|
+
region: config.get("aws.region"),
|
|
182
|
+
endpoint: config.get("aws.endpointUrl"),
|
|
183
|
+
publishToTopic: config.get("aws.sns.configVersionTopicArn"),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
await publishMessage(payload);
|
|
188
|
+
|
|
189
|
+
logger.info(
|
|
190
|
+
`successfully notified the config broker about '${payload.grant}' at version '${payload.version}' via SNS`,
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const setToUseSNS = (configSNSTopic) => {
|
|
195
|
+
return (
|
|
196
|
+
configSNSTopic &&
|
|
197
|
+
configSNSTopic !== config.default("aws.sns.configVersionTopicArn")
|
|
198
|
+
);
|
|
199
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { storeConfigVersionAndInformBroker } from "./config-store-and-inform.js";
|
|
2
2
|
import { readFileSync, existsSync, lstatSync, readdirSync } from "node:fs";
|
|
3
3
|
import { listFiles, uploadBlob } from "../s3/s3-interactions.js";
|
|
4
|
+
import {
|
|
5
|
+
isClientSetup,
|
|
6
|
+
publishMessage,
|
|
7
|
+
setupClient,
|
|
8
|
+
} from "../sns/sns-client.js";
|
|
9
|
+
import { config } from "../config/config.js";
|
|
4
10
|
|
|
5
11
|
vi.mock("node:fs", () => ({
|
|
6
12
|
existsSync: vi.fn(),
|
|
@@ -9,20 +15,6 @@ vi.mock("node:fs", () => ({
|
|
|
9
15
|
readFileSync: vi.fn(() => "file-content"),
|
|
10
16
|
}));
|
|
11
17
|
|
|
12
|
-
vi.mock("../config/config.js", () => ({
|
|
13
|
-
config: {
|
|
14
|
-
get: (key) => {
|
|
15
|
-
const values = {
|
|
16
|
-
serviceVersion: "1.2.3",
|
|
17
|
-
serviceName: "grants-config-playground",
|
|
18
|
-
"configBroker.apiEndpoint": "https://broker.unit.test",
|
|
19
|
-
"configPublish.status": "active",
|
|
20
|
-
};
|
|
21
|
-
return values[key];
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
18
|
vi.mock("../s3/s3-interactions.js", () => ({
|
|
27
19
|
listFiles: vi.fn(() => []),
|
|
28
20
|
uploadBlob: vi.fn(),
|
|
@@ -34,10 +26,13 @@ vi.mock("../broker/broker-auth-helper.js", () => ({
|
|
|
34
26
|
})),
|
|
35
27
|
}));
|
|
36
28
|
|
|
29
|
+
vi.mock("../sns/sns-client.js");
|
|
30
|
+
|
|
37
31
|
const mockLogger = {
|
|
38
32
|
info: vi.fn(),
|
|
39
33
|
warn: vi.fn(),
|
|
40
34
|
error: vi.fn(),
|
|
35
|
+
child: vi.fn(() => mockLogger),
|
|
41
36
|
};
|
|
42
37
|
|
|
43
38
|
describe("storeConfigVersionAndInformBroker", () => {
|
|
@@ -56,6 +51,15 @@ describe("storeConfigVersionAndInformBroker", () => {
|
|
|
56
51
|
}),
|
|
57
52
|
),
|
|
58
53
|
);
|
|
54
|
+
|
|
55
|
+
config.set("serviceVersion", "1.2.3");
|
|
56
|
+
config.set("serviceName", "grants-config-playground");
|
|
57
|
+
config.set("configBroker.apiEndpoint", "https://broker.unit.test");
|
|
58
|
+
config.set("configPublish.status", "active");
|
|
59
|
+
config.set(
|
|
60
|
+
"aws.sns.configVersionTopicArn",
|
|
61
|
+
"arn:aws:sns:us-east-1:123456789012:config-version-topic",
|
|
62
|
+
);
|
|
59
63
|
});
|
|
60
64
|
|
|
61
65
|
afterEach(() => {
|
|
@@ -79,124 +83,171 @@ describe("storeConfigVersionAndInformBroker", () => {
|
|
|
79
83
|
expect(fetch).not.toHaveBeenCalled();
|
|
80
84
|
});
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
describe("when configurations exist", () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
existsSync.mockReturnValue(true);
|
|
89
|
+
lstatSync.mockReturnValue({ isDirectory: () => true });
|
|
90
|
+
readdirSync
|
|
91
|
+
.mockReturnValueOnce([{ name: "grant-1", isDirectory: () => true }])
|
|
92
|
+
.mockReturnValueOnce([
|
|
93
|
+
{
|
|
94
|
+
name: "main.json",
|
|
95
|
+
isFile: () => true,
|
|
96
|
+
parentPath: "configurations/grant-1",
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should store config and inform config broker via REST API if SNS not setup", async () => {
|
|
102
|
+
//reset topic to default, should indicate not setup
|
|
103
|
+
config.set(
|
|
104
|
+
"aws.sns.configVersionTopicArn",
|
|
105
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
106
|
+
);
|
|
107
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
108
|
+
|
|
109
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
110
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
111
|
+
);
|
|
112
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
113
|
+
"successfully uploaded '1' files across '1' configs",
|
|
114
|
+
);
|
|
115
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
116
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3'",
|
|
117
|
+
);
|
|
118
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
119
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
120
|
+
expect(uploadBlob).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
122
|
+
"https://broker.unit.test/api/release-config",
|
|
88
123
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: {
|
|
126
|
+
"Content-Type": "application/json",
|
|
127
|
+
authorization: "Bearer token",
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify({
|
|
130
|
+
grant: "grant-1",
|
|
131
|
+
version: "1.2.3",
|
|
132
|
+
files: ["grant-1/1.2.3/main.json"],
|
|
133
|
+
status: "active",
|
|
134
|
+
}),
|
|
92
135
|
},
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should store config and inform config broker via SNS if setup", async () => {
|
|
140
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
141
|
+
|
|
142
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
143
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
144
|
+
);
|
|
145
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
146
|
+
"successfully uploaded '1' files across '1' configs",
|
|
147
|
+
);
|
|
148
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
149
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3' via SNS",
|
|
150
|
+
);
|
|
151
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
152
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
153
|
+
expect(uploadBlob).toHaveBeenCalledTimes(1);
|
|
154
|
+
expect(isClientSetup).toHaveBeenCalledTimes(1);
|
|
155
|
+
expect(setupClient).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(publishMessage).toHaveBeenCalledWith({
|
|
157
|
+
grant: "grant-1",
|
|
158
|
+
version: "1.2.3",
|
|
159
|
+
files: ["grant-1/1.2.3/main.json"],
|
|
160
|
+
status: "active",
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should not store or inform when already published by config broker", async () => {
|
|
165
|
+
listFiles.mockReturnValueOnce([{ Contents: ["fake-content-1"] }]);
|
|
166
|
+
|
|
167
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
168
|
+
|
|
169
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(readFileSync).not.toHaveBeenCalled();
|
|
171
|
+
expect(uploadBlob).not.toHaveBeenCalled();
|
|
172
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("should stop and print warning if no mechanism setup to contact config-broker", async () => {
|
|
176
|
+
config.set(
|
|
177
|
+
"aws.sns.configVersionTopicArn",
|
|
178
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
179
|
+
);
|
|
180
|
+
config.set("configBroker.apiEndpoint", "");
|
|
181
|
+
|
|
182
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
183
|
+
|
|
184
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
185
|
+
"config SNS topic not set, and config broker endpoint not set, so skipping release config call",
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
189
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
190
|
+
expect(isClientSetup).not.toHaveBeenCalled();
|
|
191
|
+
expect(setupClient).not.toHaveBeenCalled();
|
|
192
|
+
expect(publishMessage).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should call config broker for each config (subdirectory) found in configurations folder", async () => {
|
|
196
|
+
//reset topic to default, should indicate not setup
|
|
197
|
+
config.set(
|
|
198
|
+
"aws.sns.configVersionTopicArn",
|
|
199
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
200
|
+
);
|
|
201
|
+
readdirSync.mockRestore();
|
|
202
|
+
readdirSync
|
|
203
|
+
.mockReturnValueOnce([
|
|
204
|
+
{ name: "grant-1", isDirectory: () => true },
|
|
205
|
+
{ name: "grant-2", isDirectory: () => true },
|
|
206
|
+
])
|
|
207
|
+
.mockReturnValueOnce([
|
|
208
|
+
{
|
|
209
|
+
name: "main.json",
|
|
210
|
+
isFile: () => true,
|
|
211
|
+
parentPath: "configurations/grant-1",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "submain.json",
|
|
215
|
+
isFile: () => true,
|
|
216
|
+
parentPath: "configurations/grant-1",
|
|
217
|
+
},
|
|
218
|
+
])
|
|
219
|
+
.mockReturnValueOnce([
|
|
220
|
+
{
|
|
221
|
+
name: "main.json",
|
|
222
|
+
isFile: () => true,
|
|
223
|
+
parentPath: "configurations/grant-2",
|
|
224
|
+
},
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
228
|
+
|
|
229
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
230
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
231
|
+
);
|
|
232
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
233
|
+
"uploading 'grant-1/1.2.3/submain.json' to S3",
|
|
234
|
+
);
|
|
235
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
236
|
+
"uploading 'grant-2/1.2.3/main.json' to S3",
|
|
237
|
+
);
|
|
238
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
239
|
+
"successfully uploaded '3' files across '2' configs",
|
|
240
|
+
);
|
|
241
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
242
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3'",
|
|
243
|
+
);
|
|
244
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
245
|
+
"successfully notified the config broker about 'grant-2' at version '1.2.3'",
|
|
246
|
+
);
|
|
247
|
+
expect(listFiles).toHaveBeenCalledTimes(2);
|
|
248
|
+
expect(readFileSync).toHaveBeenCalledTimes(3);
|
|
249
|
+
expect(uploadBlob).toHaveBeenCalledTimes(3);
|
|
250
|
+
expect(fetch).toHaveBeenCalledTimes(2);
|
|
251
|
+
});
|
|
201
252
|
});
|
|
202
253
|
});
|