@@ -10,15 +10,15 @@ describe('001-update-grafana-compose-extend', () => {
10
10
expect ( context . listChanges ( ) ) . toEqual ( { } ) ;
11
11
} ) ;
12
12
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 ( ) => {
14
14
const context = new Context ( '/virtual' ) ;
15
15
context . addFile (
16
16
'./docker-compose.yaml' ,
17
17
stringify ( {
18
18
services : {
19
19
grafana : {
20
20
build : {
21
- context : './wrong-path ' ,
21
+ context : './.config ' ,
22
22
} ,
23
23
} ,
24
24
} ,
@@ -29,13 +29,32 @@ describe('001-update-grafana-compose-extend', () => {
29
29
expect ( context . listChanges ( ) ) . toEqual ( initialChanges ) ;
30
30
} ) ;
31
31
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 ( ) => {
33
33
const context = new Context ( '/virtual' ) ;
34
34
context . addFile (
35
35
'./docker-compose.yaml' ,
36
36
stringify ( {
37
37
services : {
38
38
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 : {
39
58
build : {
40
59
context : './.config' ,
41
60
} ,
@@ -48,25 +67,58 @@ describe('001-update-grafana-compose-extend', () => {
48
67
expect ( context . listChanges ( ) ) . toEqual ( initialChanges ) ;
49
68
} ) ;
50
69
51
- it . only ( 'should extend base config removing any duplicate config ' , async ( ) => {
70
+ it ( 'should remove duplicate key value pairs ' , async ( ) => {
52
71
const context = new Context ( '/virtual' ) ;
53
72
context . addFile (
54
73
'./docker-compose.yaml' ,
55
74
stringify ( {
56
75
services : {
57
76
grafana : {
58
- container_name : 'heywesty-trafficlight-panel' ,
59
77
build : {
60
78
context : './.config' ,
61
- args : {
62
- grafana_image : '${GRAFANA_IMAGE:-grafana-enterprise}' ,
63
- grafana_version : '${GRAFANA_VERSION:-9.5.3}' ,
64
- } ,
65
79
} ,
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 : '.' ,
68
93
} ,
94
+ container_name : 'heywesty-trafficlight-panel' ,
69
95
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
+ } ,
70
122
volumes : [
71
123
'./dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel' ,
72
124
'./provisioning:/etc/grafana/provisioning' ,
@@ -80,29 +132,111 @@ describe('001-update-grafana-compose-extend', () => {
80
132
stringify ( {
81
133
services : {
82
134
grafana : {
83
- user : 'root' ,
84
- container_name : 'heywesty-trafficlight-panel' ,
85
135
build : {
86
136
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
- } ,
93
137
} ,
94
- ports : [ '3000:3000/tcp' ] ,
95
138
volumes : [
96
139
'../dist:/var/lib/grafana/plugins/heywesty-trafficlight-panel' ,
97
140
'../provisioning:/etc/grafana/provisioning' ,
98
- '..:/root/heywesty-trafficlight-panel' ,
99
141
] ,
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
+ } ,
100
238
environment : {
101
239
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' ,
106
240
} ,
107
241
} ,
108
242
} ,
@@ -171,25 +305,6 @@ services:
171
305
expect ( migratedContent ) . toContain ( '# Build configuration' ) ;
172
306
expect ( migratedContent ) . toContain ( '# Inline comment' ) ;
173
307
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
- } ) ;
193
308
} ) ;
194
309
195
310
it ( 'should be idempotent' , async ( ) => {
0 commit comments