@@ -505,12 +505,12 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
505505 })
506506
507507 tests := []struct {
508- name string
509- services map [string ]* ServiceConfig
510- resources map [string ]* ResourceConfig
511- expected [] string
512- shouldError bool
513- errorMsg string
508+ name string
509+ services map [string ]* ServiceConfig
510+ resources map [string ]* ResourceConfig
511+ expectedVariations [][] string // All valid orderings (single slice for deterministic cases)
512+ shouldError bool
513+ errorMsg string
514514 }{
515515 {
516516 name : "no dependencies - alphabetical order maintained" ,
@@ -519,7 +519,9 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
519519 "alpha" : {Name : "alpha" , Uses : []string {}},
520520 "beta" : {Name : "beta" , Uses : []string {}},
521521 },
522- expected : []string {"alpha" , "beta" , "zebra" }, // Alphabetical order when no dependencies
522+ expectedVariations : [][]string {
523+ {"alpha" , "beta" , "zebra" }, // Alphabetical order when no dependencies
524+ },
523525 },
524526 {
525527 name : "simple dependency chain" ,
@@ -528,7 +530,9 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
528530 "backend" : {Name : "backend" , Uses : []string {"database" }},
529531 "database" : {Name : "database" , Uses : []string {}},
530532 },
531- expected : []string {"database" , "backend" , "frontend" },
533+ expectedVariations : [][]string {
534+ {"database" , "backend" , "frontend" },
535+ },
532536 },
533537 {
534538 name : "complex dependencies" ,
@@ -539,7 +543,10 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
539543 "storage" : {Name : "storage" , Uses : []string {"database" }},
540544 "database" : {Name : "database" , Uses : []string {}},
541545 },
542- expected : []string {"database" , "auth" , "storage" , "api" , "web" },
546+ expectedVariations : [][]string {
547+ {"database" , "auth" , "storage" , "api" , "web" }, // Original expected order
548+ {"database" , "storage" , "auth" , "api" , "web" }, // Alternative valid order
549+ },
543550 },
544551 {
545552 name : "service depending on resource" ,
@@ -550,7 +557,9 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
550557 resources : map [string ]* ResourceConfig {
551558 "database" : {Name : "database" , Type : "db.postgres" },
552559 },
553- expected : []string {"api" , "web" }, // Resource dependencies don't affect service ordering
560+ expectedVariations : [][]string {
561+ {"api" , "web" }, // Resource dependencies don't affect service ordering
562+ },
554563 },
555564 {
556565 name : "circular dependency" ,
@@ -593,12 +602,26 @@ func TestImportManagerServiceStableWithDependencyOrdering(t *testing.T) {
593602 require .Contains (t , err .Error (), tt .errorMsg )
594603 } else {
595604 require .NoError (t , err )
596- require .Len (t , result , len (tt .expected ))
605+ require .Len (t , result , len (tt .expectedVariations [0 ]))
606+
607+ // Get the actual service names for comparison
608+ actualOrder := make ([]string , len (result ))
609+ for i , svc := range result {
610+ actualOrder [i ] = svc .Name
611+ }
612+
613+ // Check if the actual order matches any of the expected variations
614+ matchesAnyVariation := false
615+ for _ , expectedVariation := range tt .expectedVariations {
616+ if slices .Equal (actualOrder , expectedVariation ) {
617+ matchesAnyVariation = true
618+ break
619+ }
620+ }
597621
598- // Check exact order for all test cases
599- for i , expected := range tt .expected {
600- assert .Equal (t , expected , result [i ].Name ,
601- "Service at position %d should be %s, got %s" , i , expected , result [i ].Name )
622+ if ! matchesAnyVariation {
623+ t .Errorf ("Actual order %v does not match any expected variations: %v" ,
624+ actualOrder , tt .expectedVariations )
602625 }
603626 }
604627 })
0 commit comments