Skip to content

Commit eaeaecf

Browse files
committed
feat(compores-extend-migration): add new tests and fix up issues related to volumes
1 parent 63bc044 commit eaeaecf

File tree

2 files changed

+226
-102
lines changed

2 files changed

+226
-102
lines changed

packages/create-plugin/src/migrations/scripts/001-update-grafana-compose-extend.test.ts

Lines changed: 159 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ describe('001-update-grafana-compose-extend', () => {
1010
expect(context.listChanges()).toEqual({});
1111
});
1212

13-
it('should not modify if grafana service with correct build context is missing', async () => {
13+
it('should not modify anything if base compose file does not exist', async () => {
1414
const context = new Context('/virtual');
1515
context.addFile(
1616
'./docker-compose.yaml',
1717
stringify({
1818
services: {
1919
grafana: {
2020
build: {
21-
context: './wrong-path',
21+
context: './.config',
2222
},
2323
},
2424
},
@@ -29,13 +29,32 @@ describe('001-update-grafana-compose-extend', () => {
2929
expect(context.listChanges()).toEqual(initialChanges);
3030
});
3131

32-
it('should not modify if base compose file is missing', async () => {
32+
it('should not modify anything if grafana service build context is not ./config', async () => {
3333
const context = new Context('/virtual');
3434
context.addFile(
3535
'./docker-compose.yaml',
3636
stringify({
3737
services: {
3838
grafana: {
39+
build: {
40+
context: './wrong-path',
41+
},
42+
},
43+
},
44+
})
45+
);
46+
const initialChanges = context.listChanges();
47+
await migrate(context);
48+
expect(context.listChanges()).toEqual(initialChanges);
49+
});
50+
51+
it('should not modify anything in other services', async () => {
52+
const context = new Context('/virtual');
53+
context.addFile(
54+
'./docker-compose.yaml',
55+
stringify({
56+
services: {
57+
otherService: {
3958
build: {
4059
context: './.config',
4160
},
@@ -48,25 +67,58 @@ describe('001-update-grafana-compose-extend', () => {
4867
expect(context.listChanges()).toEqual(initialChanges);
4968
});
5069

51-
it.only('should extend base config removing any duplicate config', async () => {
70+
it('should remove duplicate key value pairs', async () => {
5271
const context = new Context('/virtual');
5372
context.addFile(
5473
'./docker-compose.yaml',
5574
stringify({
5675
services: {
5776
grafana: {
58-
container_name: 'heywesty-trafficlight-panel',
5977
build: {
6078
context: './.config',
61-
args: {
62-
grafana_image: '${GRAFANA_IMAGE:-grafana-enterprise}',
63-
grafana_version: '${GRAFANA_VERSION:-9.5.3}',
64-
},
6579
},
66-
environment: {
67-
GF_INSTALL_PLUGINS: 'snuids-trafficlights-panel',
80+
container_name: 'heywesty-trafficlight-panel',
81+
ports: ['3000:3000/tcp'],
82+
},
83+
},
84+
})
85+
);
86+
context.addFile(
87+
'./.config/docker-compose-base.yaml',
88+
stringify({
89+
services: {
90+
grafana: {
91+
build: {
92+
context: '.',
6893
},
94+
container_name: 'heywesty-trafficlight-panel',
6995
ports: ['3000:3000/tcp'],
96+
},
97+
},
98+
})
99+
);
100+
101+
await migrate(context);
102+
103+
const result = parse(context.getFile('./docker-compose.yaml') || '');
104+
expect(result.services.grafana).toEqual({
105+
extends: {
106+
file: '.config/docker-compose-base.yaml',
107+
service: 'grafana',
108+
},
109+
});
110+
});
111+
112+
it('should merge volume paths that resolve to the same directory', async () => {
113+
const context = new Context('/virtual');
114+
context.addFile(
115+
'./docker-compose.yaml',
116+
stringify({
117+
services: {
118+
grafana: {
119+
build: {
120+
context: './.config',
121+
},
70122
volumes: [
71123
'./dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel',
72124
'./provisioning:/etc/grafana/provisioning',
@@ -80,29 +132,111 @@ describe('001-update-grafana-compose-extend', () => {
80132
stringify({
81133
services: {
82134
grafana: {
83-
user: 'root',
84-
container_name: 'heywesty-trafficlight-panel',
85135
build: {
86136
context: '.',
87-
args: {
88-
grafana_image: '${GRAFANA_IMAGE:-grafana-enterprise}',
89-
grafana_version: '${GRAFANA_VERSION:-11.5.3}',
90-
development: '${DEVELOPMENT:-false}',
91-
anonymous_auth_enabled: '${ANONYMOUS_AUTH_ENABLED:-true}',
92-
},
93137
},
94-
ports: ['3000:3000/tcp'],
95138
volumes: [
96139
'../dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel',
97140
'../provisioning:/etc/grafana/provisioning',
98-
'..:/root/heywesty-trafficlight-panel',
99141
],
142+
},
143+
},
144+
})
145+
);
146+
147+
await migrate(context);
148+
149+
const result = parse(context.getFile('./docker-compose.yaml') || '');
150+
expect(result.services.grafana).toEqual({
151+
extends: {
152+
file: '.config/docker-compose-base.yaml',
153+
service: 'grafana',
154+
},
155+
});
156+
});
157+
158+
it('should preserve volume paths that resolve to other directories', async () => {
159+
const context = new Context('/virtual');
160+
context.addFile(
161+
'./docker-compose.yaml',
162+
stringify({
163+
services: {
164+
grafana: {
165+
build: {
166+
context: './.config',
167+
},
168+
volumes: [
169+
'./another/dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel',
170+
'./provisioning:/etc/grafana/provisioning',
171+
'./something-else:/var/lib/grafana/plugins/something-else',
172+
],
173+
},
174+
},
175+
})
176+
);
177+
context.addFile(
178+
'./.config/docker-compose-base.yaml',
179+
stringify({
180+
services: {
181+
grafana: {
182+
volumes: [
183+
'../dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel',
184+
'../provisioning:/etc/grafana/provisioning',
185+
],
186+
},
187+
},
188+
})
189+
);
190+
191+
await migrate(context);
192+
193+
const result = parse(context.getFile('./docker-compose.yaml') || '');
194+
195+
expect(result.services.grafana).toEqual({
196+
extends: {
197+
file: '.config/docker-compose-base.yaml',
198+
service: 'grafana',
199+
},
200+
volumes: [
201+
'./another/dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel',
202+
'./something-else:/var/lib/grafana/plugins/something-else',
203+
],
204+
});
205+
});
206+
207+
it('should preserve non-duplicate configuration', async () => {
208+
const context = new Context('/virtual');
209+
context.addFile(
210+
'./docker-compose.yaml',
211+
stringify({
212+
services: {
213+
grafana: {
214+
build: {
215+
context: './.config',
216+
args: {
217+
grafana_version: '${GRAFANA_VERSION:-9.5.3}',
218+
},
219+
},
220+
environment: {
221+
GF_INSTALL_PLUGINS: 'snuids-trafficlights-panel',
222+
},
223+
},
224+
},
225+
})
226+
);
227+
context.addFile(
228+
'./.config/docker-compose-base.yaml',
229+
stringify({
230+
services: {
231+
grafana: {
232+
build: {
233+
context: '.',
234+
args: {
235+
grafana_version: '${GRAFANA_VERSION:-11.5.3}',
236+
},
237+
},
100238
environment: {
101239
NODE_ENV: 'development',
102-
GF_LOG_FILTERS: 'plugin.heywesty-trafficlight-panel:debug',
103-
GF_LOG_LEVEL: 'debug',
104-
GF_DATAPROXY_LOGGING: '1',
105-
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: 'heywesty-trafficlight-panel',
106240
},
107241
},
108242
},
@@ -171,25 +305,6 @@ services:
171305
expect(migratedContent).toContain('# Build configuration');
172306
expect(migratedContent).toContain('# Inline comment');
173307
expect(migratedContent).toContain('# Another inline comment');
174-
175-
// Verify the structure is still correct after migration
176-
const result = parse(migratedContent);
177-
expect(result.services.grafana).toEqual({
178-
extends: {
179-
file: '.config/docker-compose-base.yaml',
180-
service: 'grafana',
181-
},
182-
build: {
183-
args: {
184-
grafana_image: 'custom-image',
185-
grafana_version: '10.0.0',
186-
},
187-
},
188-
environment: {
189-
GF_AUTH_ANONYMOUS_ENABLED: 'true',
190-
CUSTOM_ENV: 'value',
191-
},
192-
});
193308
});
194309

195310
it('should be idempotent', async () => {

0 commit comments

Comments
 (0)