-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathmatrix_test.go
More file actions
2041 lines (1858 loc) · 62.5 KB
/
Copy pathmatrix_test.go
File metadata and controls
2041 lines (1858 loc) · 62.5 KB
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
package matrix
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
"scripts/camunda-core/pkg/versionmatrix"
"gopkg.in/yaml.v3"
"scripts/camunda-deployer/pkg/deployer"
"scripts/deploy-camunda/config"
"scripts/deploy-camunda/deploy"
)
// --- Version comparison tests ---
func TestParseVersion(t *testing.T) {
tests := []struct {
input string
wantMajor int
wantMinor int
}{
{"8.6", 8, 6},
{"8.9", 8, 9},
{"10.0", 10, 0},
{"0.1", 0, 1},
{"8", 8, 0},
{"", 0, 0},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
major, minor := parseVersion(tt.input)
if major != tt.wantMajor || minor != tt.wantMinor {
t.Errorf("parseVersion(%q) = (%d, %d), want (%d, %d)", tt.input, major, minor, tt.wantMajor, tt.wantMinor)
}
})
}
}
func TestCompareVersions(t *testing.T) {
tests := []struct {
a, b string
want int
}{
{"8.6", "8.6", 0},
{"8.7", "8.6", 1},
{"8.6", "8.7", -1},
{"8.9", "8.6", 1},
{"9.0", "8.9", 1},
{"8.9", "9.0", -1},
}
for _, tt := range tests {
t.Run(tt.a+"_vs_"+tt.b, func(t *testing.T) {
got := compareVersions(tt.a, tt.b)
if got != tt.want {
t.Errorf("compareVersions(%q, %q) = %d, want %d", tt.a, tt.b, got, tt.want)
}
})
}
}
func TestMatchesVersion(t *testing.T) {
tests := []struct {
constraint string
version string
want bool
}{
// Exact match
{"==8.9", "8.9", true},
{"==8.9", "8.8", false},
// Less than or equal
{"<=8.7", "8.6", true},
{"<=8.7", "8.7", true},
{"<=8.7", "8.8", false},
{"<=8.7", "8.9", false},
// Greater than or equal
{">=8.8", "8.8", true},
{">=8.8", "8.9", true},
{">=8.8", "8.7", false},
// Strict less than
{"<8.8", "8.7", true},
{"<8.8", "8.8", false},
// Strict greater than
{">8.7", "8.8", true},
{">8.7", "8.7", false},
// No operator means ==
{"8.9", "8.9", true},
{"8.9", "8.8", false},
// Empty constraint
{"", "8.9", false},
}
for _, tt := range tests {
t.Run(tt.constraint+"_"+tt.version, func(t *testing.T) {
got := matchesVersion(tt.constraint, tt.version)
if got != tt.want {
t.Errorf("matchesVersion(%q, %q) = %v, want %v", tt.constraint, tt.version, got, tt.want)
}
})
}
}
// --- Flow filtering tests ---
func TestFilterFlows(t *testing.T) {
pf := &PermittedFlows{
Rules: []PermittedFlowRule{
{Match: "<=8.7", Deny: []string{"upgrade-minor"}},
{Match: "==8.9", Deny: []string{"upgrade-patch", "upgrade-minor"}},
},
}
tests := []struct {
name string
version string
flows []string
want []string
}{
{
name: "8.6 denies upgrade-minor",
version: "8.6",
flows: []string{"install", "upgrade-patch", "upgrade-minor"},
want: []string{"install", "upgrade-patch"},
},
{
name: "8.7 denies upgrade-minor",
version: "8.7",
flows: []string{"install", "upgrade-patch", "upgrade-minor"},
want: []string{"install", "upgrade-patch"},
},
{
name: "8.8 allows all flows",
version: "8.8",
flows: []string{"install", "upgrade-patch", "upgrade-minor"},
want: []string{"install", "upgrade-patch", "upgrade-minor"},
},
{
name: "8.9 only allows install",
version: "8.9",
flows: []string{"install", "upgrade-patch", "upgrade-minor"},
want: []string{"install"},
},
{
name: "8.9 with only install",
version: "8.9",
flows: []string{"install"},
want: []string{"install"},
},
{
name: "8.9 with only denied flows returns empty",
version: "8.9",
flows: []string{"upgrade-patch", "upgrade-minor"},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := FilterFlows(pf, tt.version, tt.flows)
if !sliceEqual(got, tt.want) {
t.Errorf("FilterFlows(pf, %q, %v) = %v, want %v", tt.version, tt.flows, got, tt.want)
}
})
}
}
// --- Matrix filter tests ---
func TestFilter(t *testing.T) {
entries := []Entry{
{Version: "8.8", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", Platform: "gke", Enabled: true},
{Version: "8.8", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", Platform: "eks", Enabled: true},
{Version: "8.8", Scenario: "elasticsearch", Shortname: "eshy", Auth: "hybrid", Flow: "install", Platform: "", Enabled: true},
{Version: "8.8", Scenario: "oidc", Shortname: "esoi", Auth: "oidc", Flow: "upgrade-minor", Enabled: true},
{Version: "8.9", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", Platform: "gke", Enabled: true},
{Version: "8.9", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", Platform: "eks", Enabled: true},
}
t.Run("no filter returns all", func(t *testing.T) {
got := Filter(entries, FilterOptions{})
if len(got) != len(entries) {
t.Errorf("Filter with no options: got %d entries, want %d", len(got), len(entries))
}
})
t.Run("scenario filter", func(t *testing.T) {
got := Filter(entries, FilterOptions{ScenarioFilter: "oidc"})
if len(got) != 1 || got[0].Scenario != "oidc" {
t.Errorf("Filter(scenario=oidc): got %d entries, want 1 oidc entry", len(got))
}
})
t.Run("scenario filter multiple comma-separated", func(t *testing.T) {
got := Filter(entries, FilterOptions{ScenarioFilter: "oidc,elasticsearch"})
// Should match 1 oidc + 5 elasticsearch entries = 6 total
if len(got) != 6 {
t.Errorf("Filter(scenario=oidc,elasticsearch): got %d entries, want 6", len(got))
}
for _, e := range got {
if e.Scenario != "oidc" && e.Scenario != "elasticsearch" {
t.Errorf("Filter(scenario=oidc,elasticsearch): unexpected scenario %q", e.Scenario)
}
}
})
t.Run("scenario filter with spaces around commas", func(t *testing.T) {
got := Filter(entries, FilterOptions{ScenarioFilter: " oidc , elasticsearch "})
if len(got) != 6 {
t.Errorf("Filter(scenario=' oidc , elasticsearch '): got %d entries, want 6", len(got))
}
})
t.Run("flow filter", func(t *testing.T) {
got := Filter(entries, FilterOptions{FlowFilter: "upgrade-minor"})
if len(got) != 1 || got[0].Flow != "upgrade-minor" {
t.Errorf("Filter(flow=upgrade-minor): got %d entries, want 1", len(got))
}
})
t.Run("platform filter gke", func(t *testing.T) {
got := Filter(entries, FilterOptions{Platform: "gke"})
// Entries with platform="gke" match, entries with platform="" also match (no restriction)
if len(got) != 4 {
t.Errorf("Filter(platform=gke): got %d entries, want 4", len(got))
}
})
t.Run("platform filter eks", func(t *testing.T) {
got := Filter(entries, FilterOptions{Platform: "eks"})
// Entries with platform="eks" match, entries with platform="" also match (no restriction)
if len(got) != 4 {
t.Errorf("Filter(platform=eks): got %d entries, want 4", len(got))
}
})
t.Run("platform filter rosa", func(t *testing.T) {
got := Filter(entries, FilterOptions{Platform: "rosa"})
// Only entries with platform="" (no restriction) match
if len(got) != 2 {
t.Errorf("Filter(platform=rosa): got %d entries, want 2 (entries with no platform restriction)", len(got))
}
})
t.Run("shortname filter single", func(t *testing.T) {
got := Filter(entries, FilterOptions{ShortnameFilter: "esoi"})
if len(got) != 1 || got[0].Shortname != "esoi" {
t.Errorf("Filter(shortname=esoi): got %d entries, want 1 esoi entry", len(got))
}
})
t.Run("shortname filter comma-separated", func(t *testing.T) {
got := Filter(entries, FilterOptions{ShortnameFilter: "eshy,esoi"})
// Should match 1 eshy + 1 esoi = 2 total
if len(got) != 2 {
t.Errorf("Filter(shortname=eshy,esoi): got %d entries, want 2", len(got))
}
for _, e := range got {
if e.Shortname != "eshy" && e.Shortname != "esoi" {
t.Errorf("Filter(shortname=eshy,esoi): unexpected shortname %q", e.Shortname)
}
}
})
t.Run("shortname filter with spaces around commas", func(t *testing.T) {
got := Filter(entries, FilterOptions{ShortnameFilter: " eshy , esoi "})
if len(got) != 2 {
t.Errorf("Filter(shortname=' eshy , esoi '): got %d entries, want 2", len(got))
}
})
t.Run("shortname filter substring match", func(t *testing.T) {
// "esk" should match all entries with shortname "eske" (4 entries across 8.8 and 8.9)
got := Filter(entries, FilterOptions{ShortnameFilter: "esk"})
if len(got) != 4 {
t.Errorf("Filter(shortname=esk): got %d entries, want 4", len(got))
}
for _, e := range got {
if e.Shortname != "eske" {
t.Errorf("Filter(shortname=esk): unexpected shortname %q", e.Shortname)
}
}
})
t.Run("shortname filter combined with scenario filter", func(t *testing.T) {
// scenario=elasticsearch AND shortname=eshy → only the eshy entry
got := Filter(entries, FilterOptions{ScenarioFilter: "elasticsearch", ShortnameFilter: "eshy"})
if len(got) != 1 || got[0].Shortname != "eshy" {
t.Errorf("Filter(scenario=elasticsearch,shortname=eshy): got %d entries, want 1 eshy entry", len(got))
}
})
t.Run("shortname filter combined with flow filter", func(t *testing.T) {
// shortname=esoi AND flow=upgrade-minor → 1 entry
got := Filter(entries, FilterOptions{ShortnameFilter: "esoi", FlowFilter: "upgrade-minor"})
if len(got) != 1 || got[0].Shortname != "esoi" {
t.Errorf("Filter(shortname=esoi,flow=upgrade-minor): got %d entries, want 1", len(got))
}
})
t.Run("shortname filter no match", func(t *testing.T) {
got := Filter(entries, FilterOptions{ShortnameFilter: "zzzz"})
if len(got) != 0 {
t.Errorf("Filter(shortname=zzzz): got %d entries, want 0", len(got))
}
})
t.Run("shortname exact match filters precisely", func(t *testing.T) {
// "es" with ShortnameExact=true should NOT match "eske" or "eshy" or "esoi"
got := Filter(entries, FilterOptions{ShortnameFilter: "es", ShortnameExact: true})
if len(got) != 0 {
t.Errorf("Filter(shortname=es, exact=true): got %d entries, want 0 (no entry has shortname exactly 'es')", len(got))
}
})
t.Run("shortname exact match finds exact shortname", func(t *testing.T) {
// "eske" with ShortnameExact=true should match all entries with shortname=="eske"
got := Filter(entries, FilterOptions{ShortnameFilter: "eske", ShortnameExact: true})
if len(got) != 4 {
t.Errorf("Filter(shortname=eske, exact=true): got %d entries, want 4", len(got))
}
for _, e := range got {
if e.Shortname != "eske" {
t.Errorf("Filter(shortname=eske, exact=true): unexpected shortname %q", e.Shortname)
}
}
})
t.Run("shortname exact with substring does not match", func(t *testing.T) {
// "esk" with ShortnameExact=true should NOT match "eske" (substring match disabled)
got := Filter(entries, FilterOptions{ShortnameFilter: "esk", ShortnameExact: true})
if len(got) != 0 {
t.Errorf("Filter(shortname=esk, exact=true): got %d entries, want 0", len(got))
}
})
t.Run("shortname exact with comma-separated values", func(t *testing.T) {
// "eske,esoi" with ShortnameExact=true should match those exact shortnames
got := Filter(entries, FilterOptions{ShortnameFilter: "eske,esoi", ShortnameExact: true})
if len(got) != 5 {
t.Errorf("Filter(shortname=eske,esoi, exact=true): got %d entries, want 5 (4 eske + 1 esoi)", len(got))
}
for _, e := range got {
if e.Shortname != "eske" && e.Shortname != "esoi" {
t.Errorf("Filter(shortname=eske,esoi, exact=true): unexpected shortname %q", e.Shortname)
}
}
})
t.Run("shortname non-exact allows substring match", func(t *testing.T) {
// Confirm the default (ShortnameExact=false) still does substring matching
// "esk" should match "eske" entries
got := Filter(entries, FilterOptions{ShortnameFilter: "esk", ShortnameExact: false})
if len(got) != 4 {
t.Errorf("Filter(shortname=esk, exact=false): got %d entries, want 4", len(got))
}
})
t.Run("scenario+shortname fallback to scenario only when shortname unmatched", func(t *testing.T) {
// When scenario filter matches but shortname doesn't match anything,
// the fallback drops the shortname filter and uses scenario alone.
// "oidc" scenario exists, but shortname "dynamic-xyz" doesn't.
got := Filter(entries, FilterOptions{ScenarioFilter: "oidc", ShortnameFilter: "dynamic-xyz", ShortnameExact: true})
// Should fall back to scenario-only filter and find the oidc entry
if len(got) != 1 || got[0].Scenario != "oidc" {
t.Errorf("Filter(scenario=oidc, shortname=dynamic-xyz, exact=true): got %d entries, want 1 oidc entry (fallback)", len(got))
}
})
t.Run("scenario+shortname no fallback when shortname matches", func(t *testing.T) {
// When both filters match, use the combined AND result (no fallback needed).
got := Filter(entries, FilterOptions{ScenarioFilter: "elasticsearch", ShortnameFilter: "eske", ShortnameExact: true})
// Should match entries with scenario containing "elasticsearch" AND shortname exactly "eske"
if len(got) != 4 {
t.Errorf("Filter(scenario=elasticsearch, shortname=eske, exact=true): got %d entries, want 4", len(got))
}
})
t.Run("scenario+shortname fallback not triggered without scenario filter", func(t *testing.T) {
// Without a scenario filter, shortname-only filter that matches nothing returns empty.
got := Filter(entries, FilterOptions{ShortnameFilter: "dynamic-xyz", ShortnameExact: true})
if len(got) != 0 {
t.Errorf("Filter(shortname=dynamic-xyz, exact=true, no scenario): got %d entries, want 0", len(got))
}
})
// --- Tier filter tests ---
tieredEntries := []Entry{
{Version: "8.9", Scenario: "elasticsearch", Shortname: "eske", Flow: "install", Tier: 1, Enabled: true},
{Version: "8.9", Scenario: "opensearch-external", Shortname: "osex", Flow: "install", Tier: 1, Enabled: true},
{Version: "8.9", Scenario: "keycloak-mt", Shortname: "kemt", Flow: "install", Tier: 2, Enabled: true},
{Version: "8.9", Scenario: "keycloak-rba", Shortname: "kerba", Flow: "install", Tier: 2, Enabled: true},
{Version: "8.9", Scenario: "no-tier-set", Shortname: "notier", Flow: "install", Tier: 0, Enabled: true},
}
t.Run("tier filter returns only matching tier", func(t *testing.T) {
got := Filter(tieredEntries, FilterOptions{Tier: 1})
if len(got) != 3 {
t.Errorf("Filter(tier=1): got %d entries, want 3 (2 tier-1 + 1 untiered)", len(got))
}
for _, e := range got {
if e.Tier != 1 && e.Tier != 0 {
t.Errorf("Filter(tier=1): unexpected tier %d for %s", e.Tier, e.Shortname)
}
}
})
t.Run("tier filter 2 returns tier-2 and untiered", func(t *testing.T) {
got := Filter(tieredEntries, FilterOptions{Tier: 2})
if len(got) != 3 {
t.Errorf("Filter(tier=2): got %d entries, want 3 (2 tier-2 + 1 untiered)", len(got))
}
for _, e := range got {
if e.Tier != 2 && e.Tier != 0 {
t.Errorf("Filter(tier=2): unexpected tier %d for %s", e.Tier, e.Shortname)
}
}
})
t.Run("no tier filter returns all entries", func(t *testing.T) {
got := Filter(tieredEntries, FilterOptions{})
if len(got) != len(tieredEntries) {
t.Errorf("Filter(no tier): got %d entries, want %d", len(got), len(tieredEntries))
}
})
t.Run("tier filter combined with scenario filter", func(t *testing.T) {
got := Filter(tieredEntries, FilterOptions{Tier: 1, ScenarioFilter: "elasticsearch"})
if len(got) != 1 || got[0].Shortname != "eske" {
t.Errorf("Filter(tier=1, scenario=elasticsearch): got %d entries, want 1 eske", len(got))
}
})
}
// --- GroupByVersion / VersionOrder tests ---
func TestGroupByVersionAndOrder(t *testing.T) {
entries := []Entry{
{Version: "8.9", Scenario: "es"},
{Version: "8.8", Scenario: "es"},
{Version: "8.8", Scenario: "oidc"},
{Version: "8.9", Scenario: "os"},
}
groups := GroupByVersion(entries)
if len(groups["8.8"]) != 2 {
t.Errorf("GroupByVersion 8.8: got %d, want 2", len(groups["8.8"]))
}
if len(groups["8.9"]) != 2 {
t.Errorf("GroupByVersion 8.9: got %d, want 2", len(groups["8.9"]))
}
order := VersionOrder(entries)
if len(order) != 2 || order[0] != "8.9" || order[1] != "8.8" {
t.Errorf("VersionOrder: got %v, want [8.9 8.8]", order)
}
}
// --- Print tests ---
func TestPrintTable(t *testing.T) {
entries := []Entry{
{Version: "8.8", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", Platform: "gke", InfraType: "distroci", Enabled: true},
}
output, err := Print(entries, "table")
if err != nil {
t.Fatalf("Print(table): %v", err)
}
if output == "" {
t.Error("Print(table): empty output")
}
if !strings.Contains(output, "elasticsearch") || !strings.Contains(output, "8.8") || !strings.Contains(output, "Total: 1") {
t.Errorf("Print(table): missing expected content in output: %s", output)
}
if !strings.Contains(output, "INFRA-TYPE") {
t.Errorf("Print(table): missing INFRA-TYPE header in output: %s", output)
}
if !strings.Contains(output, "distroci") {
t.Errorf("Print(table): missing infra-type value 'distroci' in output: %s", output)
}
}
func TestPrintJSON(t *testing.T) {
entries := []Entry{
{Version: "8.8", Scenario: "elasticsearch", Shortname: "eske", Auth: "keycloak", Flow: "install", InfraType: "distroci", Enabled: true},
}
output, err := Print(entries, "json")
if err != nil {
t.Fatalf("Print(json): %v", err)
}
if !strings.Contains(output, `"version": "8.8"`) || !strings.Contains(output, `"scenario": "elasticsearch"`) {
t.Errorf("Print(json): missing expected JSON content in output: %s", output)
}
if !strings.Contains(output, `"infraType": "distroci"`) {
t.Errorf("Print(json): missing infraType in JSON output: %s", output)
}
}
func TestPrintInvalidFormat(t *testing.T) {
_, err := Print(nil, "xml")
if err == nil {
t.Error("Print(xml): expected error for unknown format")
}
}
func TestPrintTableEmpty(t *testing.T) {
output, err := Print(nil, "table")
if err != nil {
t.Fatalf("Print(table, empty): %v", err)
}
if !strings.Contains(output, "No matrix entries found") {
t.Errorf("Print(table, empty): expected 'No matrix entries found', got: %s", output)
}
}
// --- Integration tests using real repo config files ---
func TestGenerateWithRealConfigs(t *testing.T) {
repoRoot := findRepoRoot(t)
entries, err := Generate(repoRoot, GenerateOptions{})
if err != nil {
t.Fatalf("Generate: %v", err)
}
if len(entries) == 0 {
t.Fatal("Generate: expected entries, got 0")
}
// Verify we have entries for multiple versions
versions := VersionOrder(entries)
if len(versions) < 2 {
t.Errorf("Generate: expected entries for at least 2 versions, got %d: %v", len(versions), versions)
}
// Verify no denied flows leaked through (must stay in sync with permitted-flows.yaml)
for _, e := range entries {
if e.Version == "8.9" && e.Flow == "upgrade-patch" {
t.Errorf("Generate: 8.9 entry has denied flow %q (scenario=%s)", e.Flow, e.Scenario)
}
if (e.Version == "8.6" || e.Version == "8.7") && e.Flow == "upgrade-minor" {
t.Errorf("Generate: %s entry has denied flow upgrade-minor (scenario=%s)", e.Version, e.Scenario)
}
}
// Verify all entries are enabled (default behavior)
for _, e := range entries {
if !e.Enabled {
t.Errorf("Generate: entry %s/%s is disabled but should be filtered out by default", e.Version, e.Scenario)
}
}
// Verify infra-type is resolved for entries from versions that have it configured (8.8+).
// All entries should have a non-empty InfraType (defaulting to "preemptible").
for _, e := range entries {
if e.InfraType == "" {
t.Errorf("Generate: entry %s/%s (platform=%s) has empty InfraType; expected at least 'preemptible'",
e.Version, e.Scenario, e.Platform)
}
}
}
func TestGenerateWithVersionFilter(t *testing.T) {
repoRoot := findRepoRoot(t)
entries, err := Generate(repoRoot, GenerateOptions{
Versions: []string{"8.8"},
})
if err != nil {
t.Fatalf("Generate(versions=8.8): %v", err)
}
for _, e := range entries {
if e.Version != "8.8" {
t.Errorf("Generate(versions=8.8): unexpected version %s", e.Version)
}
}
}
func TestGenerateWithIncludeDisabled(t *testing.T) {
repoRoot := findRepoRoot(t)
withDisabled, err := Generate(repoRoot, GenerateOptions{IncludeDisabled: true})
if err != nil {
t.Fatalf("Generate(includeDisabled): %v", err)
}
withoutDisabled, err := Generate(repoRoot, GenerateOptions{IncludeDisabled: false})
if err != nil {
t.Fatalf("Generate(no includeDisabled): %v", err)
}
if len(withDisabled) < len(withoutDisabled) {
t.Errorf("Generate: withDisabled (%d) < withoutDisabled (%d); including disabled should never reduce entries",
len(withDisabled), len(withoutDisabled))
} else if len(withDisabled) == len(withoutDisabled) {
t.Logf("Generate: withDisabled=%d == withoutDisabled=%d (all scenarios may be enabled)",
len(withDisabled), len(withoutDisabled))
}
}
func TestGenerateInvalidVersion(t *testing.T) {
repoRoot := findRepoRoot(t)
_, err := Generate(repoRoot, GenerateOptions{
Versions: []string{"99.99"},
})
if err == nil {
t.Error("Generate(versions=99.99): expected error for invalid version")
}
}
// --- Config loader tests ---
func TestLoadChartVersions(t *testing.T) {
repoRoot := findRepoRoot(t)
cv, err := LoadChartVersions(repoRoot)
if err != nil {
t.Fatalf("LoadChartVersions: %v", err)
}
active := cv.ActiveVersions()
if len(active) == 0 {
t.Fatal("LoadChartVersions: no active versions")
}
// 8.10 should be alpha
found := false
for _, v := range cv.CamundaVersions.Alpha {
if v == "8.10" {
found = true
}
}
if !found {
t.Error("LoadChartVersions: 8.10 not found in alpha")
}
}
func TestLoadPermittedFlows(t *testing.T) {
repoRoot := findRepoRoot(t)
pf, err := LoadPermittedFlows(repoRoot)
if err != nil {
t.Fatalf("LoadPermittedFlows: %v", err)
}
if len(pf.Defaults.Flows) == 0 {
t.Error("LoadPermittedFlows: no default flows")
}
if len(pf.Rules) == 0 {
t.Error("LoadPermittedFlows: no rules")
}
}
func TestLoadCITestConfig(t *testing.T) {
repoRoot := findRepoRoot(t)
chartDir := filepath.Join(repoRoot, "charts", "camunda-platform-8.8")
cfg, err := LoadCITestConfig(chartDir)
if err != nil {
t.Fatalf("LoadCITestConfig: %v", err)
}
if len(cfg.Integration.Case.PR.Scenarios) == 0 {
t.Error("LoadCITestConfig: no PR scenarios")
}
}
// --- HelmVersion passthrough ---
func TestHelmVersionPassthrough(t *testing.T) {
// Decode a minimal scenario YAML and confirm HelmVersion loads.
src := []byte(`
name: elasticsearch
enabled: true
shortname: eske
flow: install
helmVersion: "4.0.0"
`)
var s CIScenario
if err := yaml.Unmarshal(src, &s); err != nil {
t.Fatalf("yaml.Unmarshal: %v", err)
}
if s.HelmVersion != "4.0.0" {
t.Errorf("CIScenario.HelmVersion = %q, want %q", s.HelmVersion, "4.0.0")
}
// Marshal an Entry carrying HelmVersion and confirm the JSON key is
// `helmVersion` — GitHub Actions matrix expressions rely on this exact key.
e := Entry{Version: "8.10", Scenario: "elasticsearch", Flow: "install", HelmVersion: "4.0.0"}
b, err := json.Marshal(e)
if err != nil {
t.Fatalf("json.Marshal: %v", err)
}
if !strings.Contains(string(b), `"helmVersion":"4.0.0"`) {
t.Errorf("Entry JSON missing helmVersion key: %s", b)
}
// Empty HelmVersion must be omitted from JSON so existing scenarios stay
// noise-free in the matrix output.
eEmpty := Entry{Version: "8.10", Scenario: "elasticsearch", Flow: "install"}
bEmpty, err := json.Marshal(eEmpty)
if err != nil {
t.Fatalf("json.Marshal empty: %v", err)
}
if strings.Contains(string(bEmpty), "helmVersion") {
t.Errorf("empty HelmVersion leaked into JSON: %s", bEmpty)
}
}
// --- RunSummary test ---
func TestPrintRunSummary(t *testing.T) {
results := []RunResult{
{Entry: Entry{Version: "8.8", Scenario: "es", Shortname: "eske", Flow: "install"}, Namespace: "matrix-88-eske"},
{Entry: Entry{Version: "8.8", Scenario: "oidc", Shortname: "esoi", Flow: "install"}, Namespace: "matrix-88-esoi", Error: os.ErrNotExist},
}
summary := PrintRunSummary(results, 10*time.Second, "")
if !strings.Contains(summary, "Total: 2") || !strings.Contains(summary, "Success: 1") || !strings.Contains(summary, "Failed: 1") {
t.Errorf("PrintRunSummary: unexpected output: %s", summary)
}
if !strings.Contains(summary, "oidc") {
t.Errorf("PrintRunSummary: expected failed entry in output: %s", summary)
}
// Non-HelmError should use the fallback "Error:" format
if !strings.Contains(summary, "Error: file does not exist") {
t.Errorf("PrintRunSummary: expected 'Error:' line for non-HelmError: %s", summary)
}
// Should show wall-clock total time
if !strings.Contains(summary, "Total time:") {
t.Errorf("PrintRunSummary: expected 'Total time:' line, got: %s", summary)
}
}
func TestPrintRunSummaryParallelShowsSum(t *testing.T) {
// Simulate parallel execution: two entries each took 30s, but wall-clock was 30s.
results := []RunResult{
{Entry: Entry{Version: "8.8", Scenario: "es", Shortname: "eske", Flow: "install"}, Namespace: "matrix-88-eske", Duration: 30 * time.Second},
{Entry: Entry{Version: "8.8", Scenario: "os", Shortname: "oske", Flow: "install"}, Namespace: "matrix-88-oske", Duration: 30 * time.Second},
}
summary := PrintRunSummary(results, 30*time.Second, "")
if !strings.Contains(summary, "Total time:") {
t.Errorf("PrintRunSummary: expected 'Total time:' line, got: %s", summary)
}
// Sum (60s) > wall-clock (30s), so "Sum of entries" should appear.
if !strings.Contains(summary, "Sum of entries:") {
t.Errorf("PrintRunSummary: expected 'Sum of entries:' line for parallel run, got: %s", summary)
}
}
func TestPrintRunSummarySequentialNoSum(t *testing.T) {
// Simulate sequential execution: wall-clock equals sum.
results := []RunResult{
{Entry: Entry{Version: "8.8", Scenario: "es", Shortname: "eske", Flow: "install"}, Namespace: "matrix-88-eske", Duration: 30 * time.Second},
}
summary := PrintRunSummary(results, 30*time.Second, "")
if !strings.Contains(summary, "Total time:") {
t.Errorf("PrintRunSummary: expected 'Total time:' line, got: %s", summary)
}
// Sum equals wall-clock, so "Sum of entries" should NOT appear.
if strings.Contains(summary, "Sum of entries:") {
t.Errorf("PrintRunSummary: unexpected 'Sum of entries:' line for sequential run, got: %s", summary)
}
}
func TestPrintRunSummaryHelmError(t *testing.T) {
helmErr := &deployer.HelmError{
Reason: "helm upgrade --install failed",
Command: "helm upgrade --install integration /very/long/path/to/charts/camunda-platform-8.9 -n ns --wait -f /tmp/long/path/base.yaml -f /tmp/long/path/gke.yaml",
Cause: fmt.Errorf("exit status 1"),
}
results := []RunResult{
{Entry: Entry{Version: "8.9", Scenario: "elasticsearch-arm", Shortname: "esarm", Flow: "install"}, Namespace: "matrix-89-esarm", Error: helmErr},
}
summary := PrintRunSummary(results, 5*time.Second, "")
// Should contain structured output
if !strings.Contains(summary, "8.9/elasticsearch-arm (esarm, flow=install)") {
t.Errorf("PrintRunSummary: expected entry header, got: %s", summary)
}
if !strings.Contains(summary, "Reason: helm upgrade --install failed: exit status 1") {
t.Errorf("PrintRunSummary: expected Reason line, got: %s", summary)
}
if !strings.Contains(summary, "Command:") {
t.Errorf("PrintRunSummary: expected Command line, got: %s", summary)
}
// Command should have shortened paths
if strings.Contains(summary, "/very/long/path/to/charts/") {
t.Errorf("PrintRunSummary: expected shortened chart path, got: %s", summary)
}
if strings.Contains(summary, "/tmp/long/path/") {
t.Errorf("PrintRunSummary: expected shortened values file paths, got: %s", summary)
}
}
func TestPrintRunSummaryWrappedHelmError(t *testing.T) {
helmErr := &deployer.HelmError{
Reason: "helm upgrade --install failed",
Command: "helm upgrade --install integration camunda/camunda-platform -n ns --version 13.5.0 --wait -f /tmp/values.yaml",
Cause: fmt.Errorf("exit status 1"),
}
// Simulate two-step upgrade wrapping
wrappedErr := fmt.Errorf("step 1: install camunda/camunda-platform@13.5.0 failed: %w", helmErr)
results := []RunResult{
{Entry: Entry{Version: "8.8", Scenario: "es", Shortname: "eske", Flow: "upgrade-patch"}, Namespace: "matrix-88-eske", Error: wrappedErr},
}
summary := PrintRunSummary(results, 5*time.Second, "")
// Should contain step context
if !strings.Contains(summary, "Step:") {
t.Errorf("PrintRunSummary: expected Step line for wrapped error, got: %s", summary)
}
if !strings.Contains(summary, "step 1: install camunda/camunda-platform@13.5.0 failed") {
t.Errorf("PrintRunSummary: expected step context in output, got: %s", summary)
}
}
func TestPrintRunSummaryEmpty(t *testing.T) {
summary := PrintRunSummary(nil, 0, "")
if !strings.Contains(summary, "No entries executed") {
t.Errorf("PrintRunSummary(nil): expected 'No entries executed', got: %s", summary)
}
}
// --- buildNamespace tests ---
func TestBuildNamespace(t *testing.T) {
tests := []struct {
name string
prefix string
entry Entry
want string
}{
{
name: "install flow without platform",
prefix: "matrix",
entry: Entry{Version: "8.8", Shortname: "eske", Flow: "install"},
want: "matrix-88-eske-inst",
},
{
name: "install flow with gke platform",
prefix: "matrix",
entry: Entry{Version: "8.8", Shortname: "eske", Flow: "install", Platform: "gke"},
want: "matrix-88-eske-inst-gke",
},
{
name: "install flow with eks platform",
prefix: "matrix",
entry: Entry{Version: "8.8", Shortname: "eske", Flow: "install", Platform: "eks"},
want: "matrix-88-eske-inst-eks",
},
{
name: "upgrade-patch flow with gke platform",
prefix: "matrix",
entry: Entry{Version: "8.7", Shortname: "es", Flow: "upgrade-patch", Platform: "gke"},
want: "matrix-87-es-upgp-gke",
},
{
name: "upgrade-minor flow without platform",
prefix: "matrix",
entry: Entry{Version: "8.8", Shortname: "kemt", Flow: "upgrade-minor"},
want: "matrix-88-kemt-upgm",
},
{
name: "alpha version with platform",
prefix: "matrix",
entry: Entry{Version: "8.9", Shortname: "oske", Flow: "install", Platform: "gke"},
want: "matrix-89-oske-inst-gke",
},
{
name: "custom prefix",
prefix: "ci",
entry: Entry{Version: "8.6", Shortname: "kemt", Flow: "install"},
want: "ci-86-kemt-inst",
},
{
name: "falls back to scenario when shortname empty",
prefix: "matrix",
entry: Entry{Version: "8.8", Scenario: "elasticsearch", Shortname: "", Flow: "install"},
want: "matrix-88-elasticsearch-inst",
},
{
name: "empty flow defaults to inst",
prefix: "matrix",
entry: Entry{Version: "8.8", Shortname: "eske"},
want: "matrix-88-eske-inst",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := buildNamespace(tt.prefix, tt.entry)
if got != tt.want {
t.Errorf("buildNamespace(%q, entry) = %q, want %q", tt.prefix, got, tt.want)
}
})
}
}
// --- flowAbbrev tests ---
func TestFlowAbbrev(t *testing.T) {
tests := []struct {
flow string
want string
}{
{"install", "inst"},
{"upgrade-patch", "upgp"},
{"upgrade-minor", "upgm"},
{"", "inst"},
{"custom-flow-long", "cust"},
{"abc", "abc"},
}
for _, tt := range tests {
t.Run(tt.flow, func(t *testing.T) {
got := flowAbbrev(tt.flow)
if got != tt.want {
t.Errorf("flowAbbrev(%q) = %q, want %q", tt.flow, got, tt.want)
}
})
}
}
// --- ingressSubdomain tests ---
func TestIngressSubdomain(t *testing.T) {
tests := []struct {
name string
baseDomain string
namespace string
want string
}{
{
name: "returns namespace when baseDomain is set",
baseDomain: "ci.distro.ultrawombat.com",
namespace: "matrix-89-eske",
want: "matrix-89-eske",
},
{
name: "returns empty when baseDomain is empty",
baseDomain: "",
namespace: "matrix-89-eske",
want: "",
},
{
name: "works with custom namespace",
baseDomain: "distribution.aws.camunda.cloud",
namespace: "ci-88-oske",
want: "ci-88-oske",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ingressSubdomain(tt.baseDomain, tt.namespace)
if got != tt.want {
t.Errorf("ingressSubdomain(%q, %q) = %q, want %q", tt.baseDomain, tt.namespace, got, tt.want)
}
})
}
}
// --- resolveKubeContext tests ---
func TestResolveKubeContext(t *testing.T) {
tests := []struct {
name string
opts RunOptions
platform string
want string
}{
{
name: "returns platform-specific context for gke",
opts: RunOptions{KubeContexts: map[string]string{"gke": "gke-ctx", "eks": "eks-ctx"}},
platform: "gke",
want: "gke-ctx",
},
{
name: "returns platform-specific context for eks",
opts: RunOptions{KubeContexts: map[string]string{"gke": "gke-ctx", "eks": "eks-ctx"}},
platform: "eks",
want: "eks-ctx",
},
{
name: "falls back to KubeContext when platform not in map",