File: quadlet_test.go

package info (click to toggle)
podman 5.7.0%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,824 kB
  • sloc: sh: 4,700; python: 2,798; perl: 1,885; ansic: 1,484; makefile: 977; ruby: 42; csh: 8
file content (1323 lines) | stat: -rw-r--r-- 51,793 bytes parent folder | download
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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
//go:build linux || freebsd

package integration

import (
	"encoding/csv"
	"fmt"
	"os"
	"path/filepath"
	"reflect"
	"regexp"
	"strings"

	"github.com/containers/podman/v5/pkg/systemd/parser"
	. "github.com/containers/podman/v5/test/utils"
	"github.com/containers/podman/v5/version"
	"github.com/mattn/go-shellwords"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gexec"
)

type quadletTestcase struct {
	data        []byte
	serviceName string
	checks      [][]string
}

// Converts "foo@bar.container" to "foo@.container"
func getGenericTemplateFile(fileName string) (bool, string) {
	extension := filepath.Ext(fileName)
	base := strings.TrimSuffix(fileName, extension)
	parts := strings.SplitN(base, "@", 2)
	if len(parts) == 2 && len(parts[1]) > 0 {
		return true, parts[0] + "@" + extension
	}
	return false, ""
}

func calcServiceName(path string) string {
	base := filepath.Base(path)
	ext := filepath.Ext(base)
	service := base[:len(base)-len(ext)]
	switch ext {
	case ".volume":
		service += "-volume"
	case ".network":
		service += "-network"
	case ".image":
		service += "-image"
	case ".build":
		service += "-build"
	case ".artifact":
		service += "-artifact"
	case ".pod":
		service += "-pod"
	}
	return service
}

func loadQuadletTestcase(path string) *quadletTestcase {
	return loadQuadletTestcaseWithServiceName(path, "")
}

func loadQuadletTestcaseWithServiceName(path, serviceName string) *quadletTestcase {
	data, err := os.ReadFile(path)
	Expect(err).ToNot(HaveOccurred())

	var service string
	if len(serviceName) > 0 {
		service = serviceName
	} else {
		service = calcServiceName(path)
	}
	service += ".service"

	checks := make([][]string, 0)

	for line := range strings.SplitSeq(string(data), "\n") {
		if strings.HasPrefix(line, "##") {
			words, err := shellwords.Parse(line[2:])
			Expect(err).ToNot(HaveOccurred())
			checks = append(checks, words)
		}
	}

	return &quadletTestcase{
		data,
		service,
		checks,
	}
}

func matchSublistAt(full []string, pos int, sublist []string) bool {
	if len(sublist) > len(full)-pos {
		return false
	}

	for i := range sublist {
		if sublist[i] != full[pos+i] {
			return false
		}
	}
	return true
}

func matchSublistRegexAt(full []string, pos int, sublist []string) bool {
	if len(sublist) > len(full)-pos {
		return false
	}

	for i := range sublist {
		matched, err := regexp.MatchString(sublist[i], full[pos+i])
		if err != nil || !matched {
			return false
		}
	}
	return true
}

func findSublist(full []string, sublist []string) int {
	if len(sublist) > len(full) {
		return -1
	}
	if len(sublist) == 0 {
		return -1
	}
	for i := 0; i < len(full)-len(sublist)+1; i++ {
		if matchSublistAt(full, i, sublist) {
			return i
		}
	}
	return -1
}

func findSublistRegex(full []string, sublist []string) int {
	if len(sublist) > len(full) {
		return -1
	}
	if len(sublist) == 0 {
		return -1
	}
	for i := 0; i < len(full)-len(sublist)+1; i++ {
		if matchSublistRegexAt(full, i, sublist) {
			return i
		}
	}
	return -1
}

func (t *quadletTestcase) assertStdErrContains(args []string, session *PodmanSessionIntegration) bool {
	return strings.Contains(session.ErrorToString(), args[0])
}

func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool {
	Expect(len(args)).To(BeNumerically(">=", 3))
	group := args[0]
	key := args[1]
	values := args[2:]

	realValues := unit.LookupAll(group, key)
	if len(realValues) != len(values) {
		return false
	}

	for i := range realValues {
		if realValues[i] != values[i] {
			return false
		}
	}
	return true
}

func (t *quadletTestcase) assertKeyIsEmpty(args []string, unit *parser.UnitFile) bool {
	Expect(args).To(HaveLen(2))
	group := args[0]
	key := args[1]

	realValues := unit.LookupAll(group, key)
	return len(realValues) == 0
}

func (t *quadletTestcase) assertKeyIsRegex(args []string, unit *parser.UnitFile) bool {
	Expect(len(args)).To(BeNumerically(">=", 3))
	group := args[0]
	key := args[1]
	values := args[2:]

	realValues := unit.LookupAll(group, key)
	if len(realValues) != len(values) {
		return false
	}

	for i := range realValues {
		matched, _ := regexp.MatchString(values[i], realValues[i])
		if !matched {
			return false
		}
	}
	return true
}

func (t *quadletTestcase) assertLastKeyIsRegex(args []string, unit *parser.UnitFile) bool {
	Expect(len(args)).To(BeNumerically(">=", 3))
	group := args[0]
	key := args[1]
	regex := args[2]

	value, ok := unit.LookupLast(group, key)
	if !ok {
		return false
	}

	matched, err := regexp.MatchString(regex, value)
	if err != nil || !matched {
		return false
	}
	return true
}

func (t *quadletTestcase) assertKeyContains(args []string, unit *parser.UnitFile) bool {
	Expect(args).To(HaveLen(3))
	group := args[0]
	key := args[1]
	value := args[2]

	realValue, ok := unit.LookupLast(group, key)
	return ok && strings.Contains(realValue, value)
}

func (t *quadletTestcase) assertKeyNotContains(args []string, unit *parser.UnitFile) bool {
	return !t.assertKeyContains(args, unit)
}

func (t *quadletTestcase) assertPodmanArgs(args []string, unit *parser.UnitFile, key string, allowRegex, globalOnly bool) bool {
	podmanArgs, _, _ := unit.LookupLastArgs("Service", key)
	if globalOnly {
		podmanCmdLocation := findSublist(podmanArgs, []string{args[0]})
		if podmanCmdLocation == -1 {
			return false
		}

		podmanArgs = podmanArgs[:podmanCmdLocation]
		args = args[1:]
	}

	var location int
	if allowRegex {
		location = findSublistRegex(podmanArgs, args)
	} else {
		location = findSublist(podmanArgs, args)
	}

	return location != -1
}

func keyValueStringToMap(keyValueString, separator string) (map[string]string, error) {
	keyValMap := make(map[string]string)
	csvReader := csv.NewReader(strings.NewReader(keyValueString))
	csvReader.Comma = []rune(separator)[0]
	keyVarList, err := csvReader.ReadAll()
	if err != nil {
		return nil, err
	}
	for _, param := range keyVarList[0] {
		key, val, _ := strings.Cut(param, "=")
		keyValMap[key] = val
	}

	return keyValMap, nil
}

func keyValMapEqualRegex(expectedKeyValMap, actualKeyValMap map[string]string) bool {
	if len(expectedKeyValMap) != len(actualKeyValMap) {
		return false
	}
	for key, expectedValue := range expectedKeyValMap {
		actualValue, ok := actualKeyValMap[key]
		if !ok {
			return false
		}
		matched, err := regexp.MatchString(expectedValue, actualValue)
		if err != nil || !matched {
			return false
		}
	}
	return true
}

func (t *quadletTestcase) assertPodmanArgsKeyVal(args []string, unit *parser.UnitFile, key string, allowRegex, globalOnly bool) bool {
	podmanArgs, _, _ := unit.LookupLastArgs("Service", key)

	if globalOnly {
		podmanCmdLocation := findSublist(podmanArgs, []string{args[0]})
		if podmanCmdLocation == -1 {
			return false
		}

		podmanArgs = podmanArgs[:podmanCmdLocation]
		args = args[1:]
	}

	expectedKeyValMap, err := keyValueStringToMap(args[2], args[1])
	if err != nil {
		return false
	}
	argKeyLocation := 0
	for {
		subListLocation := findSublist(podmanArgs[argKeyLocation:], []string{args[0]})
		if subListLocation == -1 {
			break
		}

		argKeyLocation += subListLocation
		actualKeyValMap, err := keyValueStringToMap(podmanArgs[argKeyLocation+1], args[1])
		if err != nil {
			break
		}
		if allowRegex {
			if keyValMapEqualRegex(expectedKeyValMap, actualKeyValMap) {
				return true
			}
		} else if reflect.DeepEqual(expectedKeyValMap, actualKeyValMap) {
			return true
		}

		argKeyLocation += 2

		if argKeyLocation > len(podmanArgs) {
			break
		}
	}

	return false
}

func (t *quadletTestcase) assertPodmanFinalArgs(args []string, unit *parser.UnitFile, key string) bool {
	podmanArgs, _, _ := unit.LookupLastArgs("Service", key)
	if len(podmanArgs) < len(args) {
		return false
	}
	return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args)
}

func (t *quadletTestcase) assertPodmanFinalArgsRegex(args []string, unit *parser.UnitFile, key string) bool {
	podmanArgs, _, _ := unit.LookupLastArgs("Service", key)
	if len(podmanArgs) < len(args) {
		return false
	}
	return matchSublistRegexAt(podmanArgs, len(podmanArgs)-len(args), args)
}

func (t *quadletTestcase) assertStartPodmanArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStart", false, false)
}

func (t *quadletTestcase) assertStartPodmanArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStart", true, false)
}

func (t *quadletTestcase) assertStartPodmanGlobalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStart", false, true)
}

func (t *quadletTestcase) assertStartPodmanGlobalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStart", true, true)
}

func (t *quadletTestcase) assertStartPodmanArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStart", false, false)
}

func (t *quadletTestcase) assertStartPodmanArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStart", true, false)
}

func (t *quadletTestcase) assertStartPodmanGlobalArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStart", false, true)
}

func (t *quadletTestcase) assertStartPodmanGlobalArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStart", true, true)
}

func (t *quadletTestcase) assertStartPodmanFinalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgs(args, unit, "ExecStart")
}

func (t *quadletTestcase) assertStartPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStart")
}

func (t *quadletTestcase) assertStartPrePodmanArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStartPre", false, false)
}

func (t *quadletTestcase) assertStartPrePodmanArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStartPre", true, false)
}

func (t *quadletTestcase) assertStartPrePodmanGlobalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStartPre", false, true)
}

func (t *quadletTestcase) assertStartPrePodmanGlobalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStartPre", true, true)
}

func (t *quadletTestcase) assertStartPrePodmanArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStartPre", false, false)
}

func (t *quadletTestcase) assertStartPrePodmanArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStartPre", true, false)
}

func (t *quadletTestcase) assertStartPrePodmanGlobalArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStartPre", false, true)
}

func (t *quadletTestcase) assertStartPrePodmanGlobalArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStartPre", true, true)
}

func (t *quadletTestcase) assertStartPrePodmanFinalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgs(args, unit, "ExecStartPre")
}

func (t *quadletTestcase) assertStartPrePodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStartPre")
}

func (t *quadletTestcase) assertStopPodmanArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStop", false, false)
}

func (t *quadletTestcase) assertStopPodmanGlobalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStop", false, true)
}

func (t *quadletTestcase) assertStopPodmanFinalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgs(args, unit, "ExecStop")
}

func (t *quadletTestcase) assertStopPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStop")
}

func (t *quadletTestcase) assertStopPodmanArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStop", false, false)
}

func (t *quadletTestcase) assertStopPodmanArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStop", true, false)
}

func (t *quadletTestcase) assertStopPostPodmanArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStopPost", false, false)
}

func (t *quadletTestcase) assertStopPostPodmanGlobalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecStopPost", false, true)
}

func (t *quadletTestcase) assertStopPostPodmanFinalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgs(args, unit, "ExecStopPost")
}

func (t *quadletTestcase) assertStopPostPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStopPost")
}

func (t *quadletTestcase) assertStopPostPodmanArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStopPost", false, false)
}

func (t *quadletTestcase) assertStopPostPodmanArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecStopPost", true, false)
}

func (t *quadletTestcase) assertReloadPodmanArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecReload", false, false)
}

func (t *quadletTestcase) assertReloadPodmanGlobalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgs(args, unit, "ExecReload", false, true)
}

func (t *quadletTestcase) assertReloadPodmanFinalArgs(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgs(args, unit, "ExecReload")
}

func (t *quadletTestcase) assertReloadPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanFinalArgsRegex(args, unit, "ExecReload")
}

func (t *quadletTestcase) assertReloadPodmanArgsKeyVal(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecReload", false, false)
}

func (t *quadletTestcase) assertReloadPodmanArgsKeyValRegex(args []string, unit *parser.UnitFile) bool {
	return t.assertPodmanArgsKeyVal(args, unit, "ExecReload", true, false)
}

func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool {
	Expect(args).To(HaveLen(2))
	symlink := args[0]
	expectedTarget := args[1]

	dir := filepath.Dir(unit.Path)

	target, err := os.Readlink(filepath.Join(dir, symlink))
	Expect(err).ToNot(HaveOccurred())

	return expectedTarget == target
}

func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, session *PodmanSessionIntegration) error {
	Expect(check).ToNot(BeEmpty())
	op := check[0]
	args := make([]string, 0)
	for _, a := range check[1:] {
		// Apply \n and \t as they are used in the testcases
		a = strings.ReplaceAll(a, "\\n", "\n")
		a = strings.ReplaceAll(a, "\\t", "\t")
		args = append(args, a)
	}
	invert := false
	if op[0] == '!' {
		invert = true
		op = op[1:]
	}

	var ok bool
	switch op {
	case "assert-failed":
		ok = true /* Handled separately */
	case "assert-stderr-contains":
		ok = t.assertStdErrContains(args, session)
	case "assert-key-is":
		ok = t.assertKeyIs(args, unit)
	case "assert-key-is-empty":
		ok = t.assertKeyIsEmpty(args, unit)
	case "assert-key-is-regex":
		ok = t.assertKeyIsRegex(args, unit)
	case "assert-key-contains":
		ok = t.assertKeyContains(args, unit)
	case "assert-key-not-contains":
		ok = t.assertKeyNotContains(args, unit)
	case "assert-last-key-is-regex":
		ok = t.assertLastKeyIsRegex(args, unit)
	case "assert-podman-args":
		ok = t.assertStartPodmanArgs(args, unit)
	case "assert-podman-args-regex":
		ok = t.assertStartPodmanArgsRegex(args, unit)
	case "assert-podman-args-key-val":
		ok = t.assertStartPodmanArgsKeyVal(args, unit)
	case "assert-podman-args-key-val-regex":
		ok = t.assertStartPodmanArgsKeyValRegex(args, unit)
	case "assert-podman-global-args":
		ok = t.assertStartPodmanGlobalArgs(args, unit)
	case "assert-podman-global-args-regex":
		ok = t.assertStartPodmanGlobalArgsRegex(args, unit)
	case "assert-podman-global-args-key-val":
		ok = t.assertStartPodmanGlobalArgsKeyVal(args, unit)
	case "assert-podman-global-args-key-val-regex":
		ok = t.assertStartPodmanGlobalArgsKeyValRegex(args, unit)
	case "assert-podman-final-args":
		ok = t.assertStartPodmanFinalArgs(args, unit)
	case "assert-podman-final-args-regex":
		ok = t.assertStartPodmanFinalArgsRegex(args, unit)
	case "assert-podman-pre-args":
		ok = t.assertStartPrePodmanArgs(args, unit)
	case "assert-podman-pre-args-regex":
		ok = t.assertStartPrePodmanArgsRegex(args, unit)
	case "assert-podman-pre-args-key-val":
		ok = t.assertStartPrePodmanArgsKeyVal(args, unit)
	case "assert-podman-pre-args-key-val-regex":
		ok = t.assertStartPrePodmanArgsKeyValRegex(args, unit)
	case "assert-podman-pre-global-args":
		ok = t.assertStartPrePodmanGlobalArgs(args, unit)
	case "assert-podman-pre-global-args-regex":
		ok = t.assertStartPrePodmanGlobalArgsRegex(args, unit)
	case "assert-podman-pre-global-args-key-val":
		ok = t.assertStartPrePodmanGlobalArgsKeyVal(args, unit)
	case "assert-podman-pre-global-args-key-val-regex":
		ok = t.assertStartPrePodmanGlobalArgsKeyValRegex(args, unit)
	case "assert-podman-pre-final-args":
		ok = t.assertStartPrePodmanFinalArgs(args, unit)
	case "assert-podman-pre-final-args-regex":
		ok = t.assertStartPrePodmanFinalArgsRegex(args, unit)
	case "assert-symlink":
		ok = t.assertSymlink(args, unit)
	case "assert-podman-stop-args":
		ok = t.assertStopPodmanArgs(args, unit)
	case "assert-podman-stop-global-args":
		ok = t.assertStopPodmanGlobalArgs(args, unit)
	case "assert-podman-stop-final-args":
		ok = t.assertStopPodmanFinalArgs(args, unit)
	case "assert-podman-stop-final-args-regex":
		ok = t.assertStopPodmanFinalArgsRegex(args, unit)
	case "assert-podman-stop-args-key-val":
		ok = t.assertStopPodmanArgsKeyVal(args, unit)
	case "assert-podman-stop-args-key-val-regex":
		ok = t.assertStopPodmanArgsKeyValRegex(args, unit)
	case "assert-podman-stop-post-args":
		ok = t.assertStopPostPodmanArgs(args, unit)
	case "assert-podman-stop-post-global-args":
		ok = t.assertStopPostPodmanGlobalArgs(args, unit)
	case "assert-podman-stop-post-final-args":
		ok = t.assertStopPostPodmanFinalArgs(args, unit)
	case "assert-podman-stop-post-final-args-regex":
		ok = t.assertStopPostPodmanFinalArgsRegex(args, unit)
	case "assert-podman-stop-post-args-key-val":
		ok = t.assertStopPostPodmanArgsKeyVal(args, unit)
	case "assert-podman-stop-post-args-key-val-regex":
		ok = t.assertStopPostPodmanArgsKeyValRegex(args, unit)
	case "assert-podman-reload-args":
		ok = t.assertReloadPodmanArgs(args, unit)
	case "assert-podman-reload-global-args":
		ok = t.assertReloadPodmanGlobalArgs(args, unit)
	case "assert-podman-reload-final-args":
		ok = t.assertReloadPodmanFinalArgs(args, unit)
	case "assert-podman-reload-final-args-regex":
		ok = t.assertReloadPodmanFinalArgsRegex(args, unit)
	case "assert-podman-reload-args-key-val":
		ok = t.assertReloadPodmanArgsKeyVal(args, unit)
	case "assert-podman-reload-args-key-val-regex":
		ok = t.assertReloadPodmanArgsKeyValRegex(args, unit)

	default:
		return fmt.Errorf("Unsupported assertion %s", op)
	}
	if invert {
		ok = !ok
	}

	if !ok {
		s := "(nil)"
		if unit != nil {
			s, _ = unit.ToString()
		}
		return fmt.Errorf("Failed assertion for %s: %s\n\n%s", t.serviceName, strings.Join(check, " "), s)
	}
	return nil
}

func (t *quadletTestcase) check(generateDir string, session *PodmanSessionIntegration) {
	expectFail := false
	for _, c := range t.checks {
		if c[0] == "assert-failed" {
			expectFail = true
		}
	}

	file := filepath.Join(generateDir, t.serviceName)
	_, err := os.Stat(file)
	if expectFail {
		Expect(err).To(MatchError(os.ErrNotExist))
	} else {
		Expect(err).ToNot(HaveOccurred())
	}

	var unit *parser.UnitFile
	if !expectFail {
		unit, err = parser.ParseUnitFile(file)
		Expect(err).ToNot(HaveOccurred())
	}

	for _, check := range t.checks {
		err := t.doAssert(check, unit, session)
		Expect(err).ToNot(HaveOccurred())
	}
}

var _ = Describe("quadlet system generator", func() {
	var (
		err          error
		generatedDir string
		quadletDir   string

		runQuadletTestCaseWithServiceName = func(fileName string, exitCode int, errString string, serviceName string) {
			testcase := loadQuadletTestcaseWithServiceName(filepath.Join("quadlet", fileName), serviceName)

			// Write the tested file to the quadlet dir
			err = os.WriteFile(filepath.Join(quadletDir, fileName), testcase.data, 0o644)
			Expect(err).ToNot(HaveOccurred())

			// Also copy any extra snippets
			snippetdirs := []string{fileName + ".d"}
			if ok, genericFileName := getGenericTemplateFile(fileName); ok {
				snippetdirs = append(snippetdirs, genericFileName+".d")
			}
			for _, snippetdir := range snippetdirs {
				dotdDir := filepath.Join("quadlet", snippetdir)
				if s, err := os.Stat(dotdDir); err == nil && s.IsDir() {
					dotdDirDest := filepath.Join(quadletDir, snippetdir)
					err = os.Mkdir(dotdDirDest, os.ModePerm)
					Expect(err).ToNot(HaveOccurred())
					err = CopyDirectory(dotdDir, dotdDirDest)
					Expect(err).ToNot(HaveOccurred())
				}
			}

			// Run quadlet to convert the file
			var args []string
			if isRootless() {
				args = append(args, "--user")
			}
			args = append(args, "--no-kmsg-log", generatedDir)
			session := podmanTest.Quadlet(args, quadletDir)
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(exitCode))

			// Print any stderr output
			errs := session.ErrorToString()
			if errs != "" {
				GinkgoWriter.Println("error:", session.ErrorToString())
			}
			Expect(errs).Should(ContainSubstring(errString))

			testcase.check(generatedDir, session)
		}

		runQuadletTestCase = func(fileName string, exitCode int, errString string) {
			runQuadletTestCaseWithServiceName(fileName, exitCode, errString, "")
		}

		runSuccessQuadletTestCase = func(fileName string) {
			runQuadletTestCase(fileName, 0, "")
		}

		runErrorQuadletTestCase = func(fileName, errString string) {
			runQuadletTestCase(fileName, 1, errString)
		}

		runWarningQuadletTestCase = func(fileName, errString string) {
			runQuadletTestCase(fileName, 0, errString)
		}
	)

	BeforeEach(func() {
		generatedDir = filepath.Join(podmanTest.TempDir, "generated")
		err = os.Mkdir(generatedDir, os.ModePerm)
		Expect(err).ToNot(HaveOccurred())

		quadletDir = filepath.Join(podmanTest.TempDir, "quadlet")
		err = os.Mkdir(quadletDir, os.ModePerm)
		Expect(err).ToNot(HaveOccurred())
	})

	Describe("quadlet -version", func() {
		It("Should print correct version", func() {
			session := podmanTest.Quadlet([]string{"-version"}, "/something")
			session.WaitWithDefaultTimeout()
			Expect(session).Should(ExitCleanly())
			Expect(session.OutputToString()).To(Equal(version.Version.String()))
		})
	})

	Describe("Running quadlet dryrun tests", func() {
		It("Should exit with an error because of no files are found to parse", func() {
			fileName := "basic.kube"
			testcase := loadQuadletTestcase(filepath.Join("quadlet", fileName))

			// Write the tested file to the quadlet dir
			err = os.WriteFile(filepath.Join(quadletDir, fileName), testcase.data, 0o644)
			Expect(err).ToNot(HaveOccurred())

			session := podmanTest.Quadlet([]string{"-dryrun"}, "/something")
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(0))

			current := session.ErrorToStringArray()
			expected := "No files parsed from [/something]"

			found := false
			for _, line := range current {
				if strings.Contains(line, expected) {
					found = true
					break
				}
			}
			Expect(found).To(BeTrue())
		})

		It("Should fail on bad quadlet", func() {
			quadletfile := fmt.Sprintf(`[Container]
Image=%s
BOGUS=foo
`, ALPINE)

			quadletfilePath := filepath.Join(podmanTest.TempDir, "bogus.container")
			err = os.WriteFile(quadletfilePath, []byte(quadletfile), 0o644)
			Expect(err).ToNot(HaveOccurred())
			defer os.Remove(quadletfilePath)
			session := podmanTest.Quadlet([]string{"-dryrun"}, podmanTest.TempDir)
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(1))
			Expect(session.ErrorToString()).To(ContainSubstring("converting \"bogus.container\": unsupported key 'BOGUS' in group 'Container' in " + quadletfilePath))
		})

		It("Should scan and return output for files in subdirectories", func() {
			dirName := "test_subdir"

			err = CopyDirectory(filepath.Join("quadlet", dirName), quadletDir)
			if err != nil {
				GinkgoWriter.Println("error:", err)
			}

			session := podmanTest.Quadlet([]string{"-dryrun", "-user"}, quadletDir)
			session.WaitWithDefaultTimeout()

			current := session.OutputToStringArray()
			expected := []string{
				"---mysleep.service---",
				"---mysleep_1.service---",
				"---mysleep_2.service---",
			}

			Expect(current).To(ContainElements(expected))
		})

		It("Should parse a kube file and print it to stdout", func() {
			fileName := "basic.kube"
			testcase := loadQuadletTestcase(filepath.Join("quadlet", fileName))

			// quadlet uses PODMAN env to get a stable podman path
			podmanPath, found := os.LookupEnv("PODMAN")
			if !found {
				podmanPath = podmanTest.PodmanBinary
			}

			// Write the tested file to the quadlet dir
			err = os.WriteFile(filepath.Join(quadletDir, fileName), testcase.data, 0o644)
			Expect(err).ToNot(HaveOccurred())

			session := podmanTest.Quadlet([]string{"-dryrun"}, quadletDir)
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(0))
			Expect(session.ErrorToString()).To(ContainSubstring("Loading source unit file "))

			current := session.OutputToStringArray()
			expected := []string{
				"---basic.service---",
				"## assert-podman-args \"kube\"",
				"## assert-podman-args \"play\"",
				"## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml",
				"## assert-podman-args \"--replace\"",
				"## assert-podman-args \"--service-container=true\"",
				"## assert-podman-stop-post-args \"kube\"",
				"## assert-podman-stop-post-args \"down\"",
				"## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml",
				"## assert-key-is \"Unit\" \"RequiresMountsFor\" \"%t/containers\"",
				"## assert-key-is \"Service\" \"KillMode\" \"mixed\"",
				"## assert-key-is \"Service\" \"Type\" \"notify\"",
				"## assert-key-is \"Service\" \"NotifyAccess\" \"all\"",
				"## assert-key-is \"Service\" \"Environment\" \"PODMAN_SYSTEMD_UNIT=%n\"",
				"## assert-key-is \"Service\" \"SyslogIdentifier\" \"%N\"",
				"[X-Kube]",
				"Yaml=deployment.yml",
				"[Unit]",
				"Wants=network-online.target",
				"After=network-online.target",
				fmt.Sprintf("SourcePath=%s/basic.kube", quadletDir),
				"RequiresMountsFor=%t/containers",
				"[Service]",
				"KillMode=mixed",
				"Environment=PODMAN_SYSTEMD_UNIT=%n",
				"Type=notify",
				"NotifyAccess=all",
				"SyslogIdentifier=%N",
				fmt.Sprintf("ExecStart=%s kube play --replace --service-container=true %s/deployment.yml", podmanPath, quadletDir),
				fmt.Sprintf("ExecStopPost=%s kube down %s/deployment.yml", podmanPath, quadletDir),
			}

			Expect(current).To(Equal(expected))
		})
	})

	DescribeTable("Running success quadlet test case",
		runSuccessQuadletTestCase,
		Entry("Basic container", "basic.container"),
		Entry("annotation.container", "annotation.container"),
		Entry("autoupdate.container", "autoupdate.container"),
		Entry("basepodman.container", "basepodman.container"),
		Entry("capabilities.container", "capabilities.container"),
		Entry("capabilities2.container", "capabilities2.container"),
		Entry("comment-with-continuation.container", "comment-with-continuation.container"),
		Entry("devices.container", "devices.container"),
		Entry("disableselinux.container", "disableselinux.container"),
		Entry("dns-options.container", "dns-options.container"),
		Entry("dns-search.container", "dns-search.container"),
		Entry("dns.container", "dns.container"),
		Entry("env-file.container", "env-file.container"),
		Entry("env-host-false.container", "env-host-false.container"),
		Entry("env-host.container", "env-host.container"),
		Entry("env.container", "env.container"),
		Entry("entrypoint.container", "entrypoint.container"),
		Entry("escapes.container", "escapes.container"),
		Entry("exec.container", "exec.container"),
		Entry("group-add.container", "group-add.container"),
		Entry("health.container", "health.container"),
		Entry("host.container", "host.container"),
		Entry("httpproxy-false.container", "httpproxy-false.container"),
		Entry("httpproxy-true.container", "httpproxy-true.container"),
		Entry("hostname.container", "hostname.container"),
		Entry("idmapping.container", "idmapping.container"),
		Entry("image.container", "image.container"),
		Entry("install.container", "install.container"),
		Entry("ip.container", "ip.container"),
		Entry("label.container", "label.container"),
		Entry("line-continuation-whitespace.container", "line-continuation-whitespace.container"),
		Entry("logdriver.container", "logdriver.container"),
		Entry("logopt.container", "logopt.container"),
		Entry("mask.container", "mask.container"),
		Entry("memory.container", "memory.container"),
		Entry("name.container", "name.container"),
		Entry("nestedselinux.container", "nestedselinux.container"),
		Entry("network.container", "network.container"),
		Entry("notify.container", "notify.container"),
		Entry("notify-healthy.container", "notify-healthy.container"),
		Entry("oneshot.container", "oneshot.container"),
		Entry("other-sections.container", "other-sections.container"),
		Entry("podmanargs.container", "podmanargs.container"),
		Entry("ports.container", "ports.container"),
		Entry("ports_ipv6.container", "ports_ipv6.container"),
		Entry("pull.container", "pull.container"),
		Entry("quotes.container", "quotes.container"),
		Entry("readonly.container", "readonly.container"),
		Entry("readonly-tmpfs.container", "readonly-tmpfs.container"),
		Entry("readonly-notmpfs.container", "readonly-notmpfs.container"),
		Entry("readwrite-notmpfs.container", "readwrite-notmpfs.container"),
		Entry("volatiletmp-readwrite.container", "volatiletmp-readwrite.container"),
		Entry("volatiletmp-readonly.container", "volatiletmp-readonly.container"),
		Entry("remap-auto.container", "remap-auto.container"),
		Entry("remap-auto2.container", "remap-auto2.container"),
		Entry("remap-keep-id.container", "remap-keep-id.container"),
		Entry("remap-keep-id2.container", "remap-keep-id2.container"),
		Entry("remap-manual.container", "remap-manual.container"),
		Entry("rootfs.container", "rootfs.container"),
		Entry("seccomp.container", "seccomp.container"),
		Entry("secrets.container", "secrets.container"),
		Entry("selinux.container", "selinux.container"),
		Entry("shmsize.container", "shmsize.container"),
		Entry("stopsigal.container", "stopsignal.container"),
		Entry("stoptimeout.container", "stoptimeout.container"),
		Entry("subidmapping.container", "subidmapping.container"),
		Entry("sysctl.container", "sysctl.container"),
		Entry("timezone.container", "timezone.container"),
		Entry("ulimit.container", "ulimit.container"),
		Entry("unmask.container", "unmask.container"),
		Entry("user.container", "user.container"),
		Entry("userns.container", "userns.container"),
		Entry("workingdir.container", "workingdir.container"),
		Entry("Container - global args", "globalargs.container"),
		Entry("Container - Containers Conf Modules", "containersconfmodule.container"),
		Entry("merged.container", "merged.container"),
		Entry("merged-override.container", "merged-override.container"),
		Entry("template@.container", "template@.container"),
		Entry("template@instance.container", "template@instance.container"),
		Entry("Unit After Override", "unit-after-override.container"),
		Entry("NetworkAlias", "network-alias.container"),
		Entry("CgroupMode", "cgroups-mode.container"),
		Entry("Container - No Default Dependencies", "no_deps.container"),
		Entry("retry.container", "retry.container"),
		Entry("reloadcmd.container", "reloadcmd.container"),
		Entry("reloadsignal.container", "reloadsignal.container"),

		Entry("basic.volume", "basic.volume"),
		Entry("device-copy.volume", "device-copy.volume"),
		Entry("device.volume", "device.volume"),
		Entry("label.volume", "label.volume"),
		Entry("name.volume", "name.volume"),
		Entry("podmanargs.volume", "podmanargs.volume"),
		Entry("uid.volume", "uid.volume"),
		Entry("image.volume", "image.volume"),
		Entry("Volume - global args", "globalargs.volume"),
		Entry("Volume - Containers Conf Modules", "containersconfmodule.volume"),
		Entry("Volume - Type=bind", "device-bind.volume"),

		Entry("Absolute Path", "absolute.path.kube"),
		Entry("Basic kube", "basic.kube"),
		Entry("Kube - ConfigMap", "configmap.kube"),
		Entry("Kube - Exit Code Propagation", "exit_code_propagation.kube"),
		Entry("Kube - Logdriver", "logdriver.kube"),
		Entry("Kube - Logopt", "logopt.kube"),
		Entry("Kube - Network", "network.kube"),
		Entry("Kube - PodmanArgs", "podmanargs.kube"),
		Entry("Kube - Publish IPv4 ports", "ports.kube"),
		Entry("Kube - Publish IPv6 ports", "ports_ipv6.kube"),
		Entry("Kube - User Remap Auto with IDs", "remap-auto2.kube"),
		Entry("Kube - User Remap Auto", "remap-auto.kube"),
		Entry("Syslog Identifier", "syslog.identifier.kube"),
		Entry("Kube - Working Directory YAML Absolute Path", "workingdir-yaml-abs.kube"),
		Entry("Kube - Working Directory YAML Relative Path", "workingdir-yaml-rel.kube"),
		Entry("Kube - Working Directory Unit", "workingdir-unit.kube"),
		Entry("Kube - Multiple YAML entries", "multiple-yaml.kube"),
		Entry("Kube - Working Directory already in Service", "workingdir-service.kube"),
		Entry("Kube - global args", "globalargs.kube"),
		Entry("Kube - Containers Conf Modules", "containersconfmodule.kube"),
		Entry("Kube - Service Type=oneshot", "oneshot.kube"),
		Entry("Kube - Down force", "downforce.kube"),

		Entry("Network - Basic", "basic.network"),
		Entry("Network - Disable DNS", "disable-dns.network"),
		Entry("Network - DNS", "dns.network"),
		Entry("Network - Driver", "driver.network"),
		Entry("Network - Gateway", "gateway.network"),
		Entry("Network - IPAM Driver", "ipam-driver.network"),
		Entry("Network - IPv6", "ipv6.network"),
		Entry("Network - InterfaceName network", "interface-name.network"),
		Entry("Network - Internal network", "internal.network"),
		Entry("Network - Label", "label.network"),
		Entry("Network - Multiple Options", "options.multiple.network"),
		Entry("Network - Name", "name.network"),
		Entry("Network - Options", "options.network"),
		Entry("Network - PodmanArgs", "podmanargs.network"),
		Entry("Network - Range", "range.network"),
		Entry("Network - Subnets", "subnets.network"),
		Entry("Network - multiple subnet, gateway and range", "subnet-trio.multiple.network"),
		Entry("Network - subnet, gateway and range", "subnet-trio.network"),
		Entry("Network - global args", "globalargs.network"),
		Entry("Network - Containers Conf Modules", "containersconfmodule.network"),
		Entry("Network - Delete on stop", "delete.network"),

		Entry("Image - Basic", "basic.image"),
		Entry("Image - Architecture", "arch.image"),
		Entry("Image - Auth File", "auth.image"),
		Entry("Image - Certificates", "certs.image"),
		Entry("Image - Credentials", "creds.image"),
		Entry("Image - Decryption Key", "decrypt.image"),
		Entry("Image - OS Key", "os.image"),
		Entry("Image - Policy Key", "policy.image"),
		Entry("Image - Variant Key", "variant.image"),
		Entry("Image - All Tags", "all-tags.image"),
		Entry("Image - TLS Verify", "tls-verify.image"),
		Entry("Image - Arch and OS", "arch-os.image"),
		Entry("Image - global args", "globalargs.image"),
		Entry("Image - Containers Conf Modules", "containersconfmodule.image"),
		Entry("Image - Unit After Override", "unit-after-override.image"),
		Entry("Image - No Default Dependencies", "no_deps.image"),
		Entry("Image - Retry", "retry.image"),

		Entry("Build - Basic", "basic.build"),
		Entry("Build - Annotation Key", "annotation.build"),
		Entry("Build - Arch Key", "arch.build"),
		Entry("Build - AuthFile Key", "authfile.build"),
		Entry("Build - DNS Key", "dns.build"),
		Entry("Build - DNSOptions Key", "dns-options.build"),
		Entry("Build - DNSSearch Key", "dns-search.build"),
		Entry("Build - Environment Key", "env.build"),
		Entry("Build - File Key absolute", "file-abs.build"),
		Entry("Build - File Key relative", "file-rel.build"),
		Entry("Build - File Key HTTP(S) URL", "file-https.build"),
		Entry("Build - ForceRM Key", "force-rm.build"),
		Entry("Build - GlobalArgs", "globalargs.build"),
		Entry("Build - GroupAdd Key", "group-add.build"),
		Entry("Build - IgnoreFile Key", "ignorefile.build"),
		Entry("Build - Containers Conf Modules", "containersconfmodule.build"),
		Entry("Build - Label Key", "label.build"),
		Entry("Build - Multiple Tags", "multiple-tags.build"),
		Entry("Build - Network Key host", "network.build"),
		Entry("Build - PodmanArgs", "podmanargs.build"),
		Entry("Build - BuildArg Key", "buildarg.build"),
		Entry("Build - Pull Key", "pull.build"),
		Entry("Build - Secrets", "secrets.build"),
		Entry("Build - SetWorkingDirectory is absolute path", "setworkingdirectory-is-abs.build"),
		Entry("Build - SetWorkingDirectory is absolute File= path", "setworkingdirectory-is-file-abs.build"),
		Entry("Build - SetWorkingDirectory is relative path", "setworkingdirectory-is-rel.build"),
		Entry("Build - SetWorkingDirectory is relative File= path", "setworkingdirectory-is-file-rel.build"),
		Entry("Build - SetWorkingDirectory is https://.git URL", "setworkingdirectory-is-https-git.build"),
		Entry("Build - SetWorkingDirectory is git:// URL", "setworkingdirectory-is-git.build"),
		Entry("Build - SetWorkingDirectory is github.com URL", "setworkingdirectory-is-github.build"),
		Entry("Build - SetWorkingDirectory is archive URL", "setworkingdirectory-is-archive.build"),
		Entry("Build - Target Key", "target.build"),
		Entry("Build - TLSVerify Key", "tls-verify.build"),
		Entry("Build - Variant Key", "variant.build"),
		Entry("Build - No Default Dependencies", "no_deps.build"),
		Entry("Build - Retry", "retry.build"),
		Entry("Build - No WorkingDirectory with systemd specifier", "no-workingdirectory-systemd-specifier.build"),

		Entry("Artifact - Basic", "basic.artifact"),
		Entry("Artifact - Options", "options.artifact"),

		Entry("Pod - Basic", "basic.pod"),
		Entry("Pod - DNS", "dns.pod"),
		Entry("Pod - DNS Option", "dns-option.pod"),
		Entry("Pod - DNS Search", "dns-search.pod"),
		Entry("Pod - Host", "host.pod"),
		Entry("Pod - HostName", "hostname.pod"),
		Entry("Pod - IP", "ip.pod"),
		Entry("Pod - Label", "label.pod"),
		Entry("Pod - Name", "name.pod"),
		Entry("Pod - Network", "network.pod"),
		Entry("Pod - PodmanArgs", "podmanargs.pod"),
		Entry("Pod - NetworkAlias", "network-alias.pod"),
		Entry("Pod - Remap auto", "remap-auto.pod"),
		Entry("Pod - Remap auto2", "remap-auto2.pod"),
		Entry("Pod - Remap keep-id", "remap-keep-id.pod"),
		Entry("Pod - Remap manual", "remap-manual.pod"),
		Entry("Pod - Shm Size", "shmsize.pod"),
		Entry("Pod - StopTimeout", "stoptimeout.pod"),
		Entry("Pod - Service Environment", "service-environment.pod"),
	)

	DescribeTable("Running expected warning quadlet test case",
		runWarningQuadletTestCase,
		Entry("label-unsupported-escape.container", "label-unsupported-escape.container", "unsupported escape char"),
		Entry("shortname.container", "shortname.container", "Warning: shortname.container specifies the image \"shortname\" which not a fully qualified image name. This is not ideal for performance and security reasons. See the podman-pull manpage discussion of short-name-aliases.conf for details."),

		Entry("Unsupported Service Key - User", "service-user.container", "Warning: using key User in the Service group is not supported"),
		Entry("Unsupported Service Key - Group", "service-group.container", "Warning: using key Group in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.build", "service-dynamicuser.build", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.container", "service-dynamicuser.container", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.image", "service-dynamicuser.image", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.kube", "service-dynamicuser.kube", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.network", "service-dynamicuser.network", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.pod", "service-dynamicuser.pod", "Warning: using key DynamicUser in the Service group is not supported"),
		Entry("Unsupported Service Key - DynamicUser.volume", "service-dynamicuser.volume", "Warning: using key DynamicUser in the Service group is not supported"),

		Entry("exec-unsupported-escape.container", "exec-unsupported-escape.container", "unsupported escape char"),
		Entry("reloadcmd-unsupported-escape.container", "reloadcmd-unsupported-escape.container", "unsupported escape char"),
	)

	DescribeTable("Running expected error quadlet test case",
		runErrorQuadletTestCase,
		Entry("idmapping-with-remap.container", "idmapping-with-remap.container", "converting \"idmapping-with-remap.container\": deprecated Remap keys are set along with explicit mapping keys"),
		Entry("noimage.container", "noimage.container", "converting \"noimage.container\": no Image or Rootfs key specified"),
		Entry("pod.non-quadlet.container", "pod.non-quadlet.container", "converting \"pod.non-quadlet.container\": pod test-pod is not Quadlet based"),
		Entry("pod.not-found.container", "pod.not-found.container", "converting \"pod.not-found.container\": quadlet pod unit not-found.pod does not exist"),
		Entry("subidmapping-with-remap.container", "subidmapping-with-remap.container", "converting \"subidmapping-with-remap.container\": deprecated Remap keys are set along with explicit mapping keys"),
		Entry("userns-with-remap.container", "userns-with-remap.container", "converting \"userns-with-remap.container\": deprecated Remap keys are set along with explicit mapping keys"),
		Entry("reloadboth.container", "reloadboth.container", "converting \"reloadboth.container\": ReloadCmd and ReloadSignal are mutually exclusive but both are set"),
		Entry("dependent.error.container", "dependent.error.container", "converting \"dependent.error.container\": unable to translate dependency for basic.container"),

		Entry("image-no-image.volume", "image-no-image.volume", "converting \"image-no-image.volume\": the key Image is mandatory when using the image driver"),
		Entry("Volume - Quadlet image (.build) not found", "build-not-found.quadlet.volume", "converting \"build-not-found.quadlet.volume\": requested Quadlet image not-found.build was not found"),
		Entry("Volume - Quadlet image (.image) not found", "image-not-found.quadlet.volume", "converting \"image-not-found.quadlet.volume\": requested Quadlet image not-found.image was not found"),

		Entry("Kube - User Remap Manual", "remap-manual.kube", "converting \"remap-manual.kube\": RemapUsers=manual is not supported"),
		Entry("Kube - Multiple Yaml and SetWorkingDir=yaml", "multiple-yaml-set-working-dir-yaml.kube", "converting \"multiple-yaml-set-working-dir-yaml.kube\": SetWorkingDirectory=yaml is only supported when a single Yaml key is provided"),

		Entry("Network - Gateway not enough Subnet", "gateway.less-subnet.network", "converting \"gateway.less-subnet.network\": cannot set more gateways than subnets"),
		Entry("Network - Gateway without Subnet", "gateway.no-subnet.network", "converting \"gateway.no-subnet.network\": cannot set gateway or range without subnet"),
		Entry("Network - Range not enough Subnet", "range.less-subnet.network", "converting \"range.less-subnet.network\": cannot set more ranges than subnets"),
		Entry("Network - Range without Subnet", "range.no-subnet.network", "converting \"range.no-subnet.network\": cannot set gateway or range without subnet"),

		Entry("Image - No Image", "no-image.image", "converting \"no-image.image\": no Image key specified"),

		Entry("Build - File Key relative no WD", "file-rel-no-wd.build", "converting \"file-rel-no-wd.build\": relative path in File key requires SetWorkingDirectory key to be set"),
		Entry("Build - Neither WorkingDirectory nor File Key", "neither-workingdirectory-nor-file.build", "converting \"neither-workingdirectory-nor-file.build\": neither SetWorkingDirectory, nor File key specified"),
		Entry("Build - No ImageTag Key", "no-imagetag.build", "converting \"no-imagetag.build\": no ImageTag key specified"),
		Entry("emptyline.container", "emptyline.container", "converting \"emptyline.container\": no Image or Rootfs key specified"),

		Entry("Mount - Missing source=...", "mount-source-missing.container", "converting \"mount-source-missing.container\": source cannot be empty"),
	)

	DescribeTable("Running success quadlet with ServiceName test case",
		func(fileName, serviceName string) {
			runQuadletTestCaseWithServiceName(fileName, 0, "", serviceName)
		},
		Entry("Build", "service-name.build", "basic"),
		Entry("Container", "service-name.container", "basic"),
		Entry("Image", "service-name.image", "basic"),
		Entry("Kube", "service-name.kube", "basic"),
		Entry("Network", "service-name.network", "basic"),
		Entry("Pod", "service-name.pod", "basic"),
		Entry("Volume", "service-name.volume", "basic"),
	)

	DescribeTable("Running quadlet success test case with dependencies",
		func(fileName string, dependencyFiles []string) {
			// Write additional files this test depends on to the quadlet dir
			for _, dependencyFileName := range dependencyFiles {
				dependencyTestCase := loadQuadletTestcase(filepath.Join("quadlet", dependencyFileName))
				err = os.WriteFile(filepath.Join(quadletDir, dependencyFileName), dependencyTestCase.data, 0o644)
				Expect(err).ToNot(HaveOccurred())
			}

			runSuccessQuadletTestCase(fileName)
		},
		Entry("Container - Mount", "mount.container", []string{"basic.image", "basic.volume", "basic.artifact"}),
		Entry("Container - Quadlet Network", "network.quadlet.container", []string{"basic.network"}),
		Entry("Container - Quadlet Volume", "volume.container", []string{"basic.volume"}),
		Entry("Container - Mount overriding service name", "mount.servicename.container", []string{"service-name.volume"}),
		Entry("Container - Quadlet Network overriding service name", "network.quadlet.servicename.container", []string{"service-name.network"}),
		Entry("Container - Quadlet Volume overriding service name", "volume.servicename.container", []string{"service-name.volume"}),
		Entry("Container - Quadlet build with multiple tags", "build.multiple-tags.container", []string{"multiple-tags.build"}),
		Entry("Container - Artifact Mount", "artifact-mount.container", []string{"basic.artifact"}),
		Entry("Container - Reuse another container's network", "network.reuse.container", []string{"basic.container"}),
		Entry("Container - Reuse another named container's network", "network.reuse.name.container", []string{"name.container"}),
		Entry("Container - Reuse another container's network", "a.network.reuse.container", []string{"basic.container"}),
		Entry("Container - Reuse another named container's network", "a.network.reuse.name.container", []string{"name.container"}),
		Entry(
			"Container - Dependency between quadlet units",
			"dependent.container",
			[]string{
				"basic.artifact",
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),
		Entry(
			"Container - Template with Volume Template dependency",
			"template-dependency@.container",
			[]string{
				"template-dependency@.volume",
				"template-dependency@.network",
			},
		),

		Entry("Volume - Quadlet image (.build)", "build.quadlet.volume", []string{"basic.build"}),
		Entry("Volume - Quadlet image (.image)", "image.quadlet.volume", []string{"basic.image"}),
		Entry("Volume - Quadlet image (.build) overriding service name", "build.quadlet.servicename.volume", []string{"service-name.build"}),
		Entry("Volume - Quadlet image (.image) overriding service name", "image.quadlet.servicename.volume", []string{"service-name.image"}),
		Entry(
			"Volume - Dependency between quadlet units",
			"dependent.volume",
			[]string{
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),

		Entry("Kube - Quadlet Network", "network.quadlet.kube", []string{"basic.network"}),
		Entry("Kube - Quadlet Network overriding service name", "network.quadlet.servicename.kube", []string{"service-name.network"}),
		Entry(
			"Kube - Dependency between quadlet units",
			"dependent.kube",
			[]string{
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),

		Entry("Build - Network Key quadlet", "network.quadlet.build", []string{"basic.network"}),
		Entry("Build - Volume Key", "volume.build", []string{"basic.volume"}),
		Entry("Build - Volume Key quadlet", "volume.quadlet.build", []string{"basic.volume"}),
		Entry("Build - Network Key quadlet overriding service name", "network.quadlet.servicename.build", []string{"service-name.network"}),
		Entry("Build - Volume Key quadlet overriding service name", "volume.quadlet.servicename.build", []string{"service-name.volume"}),
		Entry(
			"Build - Dependency between quadlet units",
			"dependent.build",
			[]string{
				"basic.artifact",
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),

		Entry("Pod - Quadlet Network", "network.quadlet.pod", []string{"basic.network"}),
		Entry("Pod - Quadlet Volume", "volume.pod", []string{"basic.volume"}),
		Entry("Pod - Quadlet Network overriding service name", "network.servicename.quadlet.pod", []string{"service-name.network"}),
		Entry("Pod - Quadlet Volume overriding service name", "volume.servicename.pod", []string{"service-name.volume"}),
		Entry("Pod - Do not autostart a container with pod", "startwithpod.pod", []string{"startwithpod_no.container", "startwithpod_yes.container"}),
		Entry(
			"Pod - Dependency between quadlet units",
			"dependent.pod",
			[]string{
				"basic.artifact",
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),

		Entry(
			"Image - Dependency between quadlet units",
			"dependent.image",
			[]string{
				"basic.artifact",
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),

		Entry(
			"Network - Dependency between quadlet units",
			"dependent.network",
			[]string{
				"basic.artifact",
				"basic.build",
				"basic.container",
				"basic.image",
				"basic.kube",
				"basic.network",
				"basic.pod",
				"basic.volume",
			},
		),
	)
})