@@ -768,50 +768,89 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
768
768
})
769
769
770
770
t .Run ("profile_list" , func (t * testing.T ) {
771
+ // helper function to run command then, return target profile line and running time.
772
+ extractrofileListFunc := func (rr * RunResult ) string {
773
+ listLines := strings .Split (strings .TrimSpace (rr .Stdout .String ()), "\n " )
774
+ for i := 3 ; i < (len (listLines ) - 1 ); i ++ {
775
+ profileLine := listLines [i ]
776
+ if strings .Contains (profileLine , profile ) {
777
+ return profileLine
778
+ }
779
+ }
780
+ return ""
781
+ }
782
+
771
783
// List profiles
784
+ start := time .Now ()
772
785
rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" ))
786
+ elapsed := time .Since (start )
773
787
if err != nil {
774
788
t .Errorf ("failed to list profiles: args %q : %v" , rr .Command (), err )
775
789
}
790
+ profileLine := extractrofileListFunc (rr )
791
+ if profileLine == "" {
792
+ t .Errorf ("expected 'profile list' output to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
793
+ }
776
794
777
- // Table output
778
- listLines := strings .Split (strings .TrimSpace (rr .Stdout .String ()), "\n " )
779
- profileExists := false
780
- for i := 3 ; i < (len (listLines ) - 1 ); i ++ {
781
- profileLine := listLines [i ]
782
- if strings .Contains (profileLine , profile ) {
783
- profileExists = true
784
- break
785
- }
795
+ // List profiles with light option.
796
+ start = time .Now ()
797
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-l" ))
798
+ lightElapsed := time .Since (start )
799
+ if err != nil {
800
+ t .Errorf ("failed to list profiles: args %q : %v" , lrr .Command (), err )
786
801
}
787
- if ! profileExists {
788
- t .Errorf ("expected 'profile list' output to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
802
+ profileLine = extractrofileListFunc (lrr )
803
+ if profileLine == "" || ! strings .Contains (profileLine , "Skipped" ) {
804
+ t .Errorf ("expected 'profile list' output to include %q with 'Skipped' status but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
805
+ }
806
+
807
+ if elapsed < (lightElapsed * 2 ) {
808
+ t .Errorf ("expected running time of '%q' is less than half of '%q'." , lrr .Command (), rr .Command ())
789
809
}
790
810
})
791
811
792
812
t .Run ("profile_json_output" , func (t * testing.T ) {
793
- // Json output
794
- rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "--output" , "json" ))
813
+ extractProfileObjFunc := func (rr * RunResult ) * config.Profile {
814
+ var jsonObject map [string ][]config.Profile
815
+ err := json .Unmarshal (rr .Stdout .Bytes (), & jsonObject )
816
+ if err != nil {
817
+ t .Errorf ("failed to decode json from profile list: args %q: %v" , rr .Command (), err )
818
+ return nil
819
+ }
820
+
821
+ for _ , profileObject := range jsonObject ["valid" ] {
822
+ if profileObject .Name == profile {
823
+ return & profileObject
824
+ }
825
+ }
826
+ return nil
827
+ }
828
+
829
+ start := time .Now ()
830
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" ))
831
+ elapsed := time .Since (start )
795
832
if err != nil {
796
833
t .Errorf ("failed to list profiles with json format. args %q: %v" , rr .Command (), err )
797
834
}
798
- var jsonObject map [string ][]map [string ]interface {}
799
- err = json .Unmarshal (rr .Stdout .Bytes (), & jsonObject )
800
- if err != nil {
801
- t .Errorf ("failed to decode json from profile list: args %q: %v" , rr .Command (), err )
835
+ pr := extractProfileObjFunc (rr )
836
+ if pr == nil {
837
+ t .Errorf ("expected the json of 'profile list' to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
802
838
}
803
- validProfiles := jsonObject ["valid" ]
804
- profileExists := false
805
- for _ , profileObject := range validProfiles {
806
- if profileObject ["Name" ] == profile {
807
- profileExists = true
808
- break
809
- }
839
+
840
+ start = time .Now ()
841
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" , "--light" ))
842
+ lightElapsed := time .Since (start )
843
+ if err != nil {
844
+ t .Errorf ("failed to list profiles with json format. args %q: %v" , lrr .Command (), err )
810
845
}
811
- if ! profileExists {
812
- t .Errorf ("expected the json of 'profile list' to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
846
+ pr = extractProfileObjFunc (lrr )
847
+ if pr == nil || pr .Status != "Skipped" {
848
+ t .Errorf ("expected the json of 'profile list' to include 'Skipped' status for %q but got *%q*. args: %q" , profile , lrr .Stdout .String (), lrr .Command ())
813
849
}
814
850
851
+ if elapsed < (lightElapsed * 2 ) {
852
+ t .Errorf ("expected running time of '%q' is less than half of '%q'." , lrr .Command (), rr .Command ())
853
+ }
815
854
})
816
855
}
817
856
0 commit comments