@@ -768,50 +768,98 @@ 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 from table output.
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
+ t .Logf ("Took %q to run %q" , elapsed , rr .Command ())
776
791
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
- }
786
- }
787
- if ! profileExists {
792
+ profileLine := extractrofileListFunc (rr )
793
+ if profileLine == "" {
788
794
t .Errorf ("expected 'profile list' output to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
789
795
}
796
+
797
+ // List profiles with light option.
798
+ start = time .Now ()
799
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-l" ))
800
+ lightElapsed := time .Since (start )
801
+ if err != nil {
802
+ t .Errorf ("failed to list profiles: args %q : %v" , lrr .Command (), err )
803
+ }
804
+ t .Logf ("Took %q to run %q" , lightElapsed , lrr .Command ())
805
+
806
+ profileLine = extractrofileListFunc (lrr )
807
+ if profileLine == "" || ! strings .Contains (profileLine , "Skipped" ) {
808
+ t .Errorf ("expected 'profile list' output to include %q with 'Skipped' status but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
809
+ }
810
+
811
+ if elapsed < (lightElapsed * 2 ) {
812
+ t .Errorf ("expected running time of '%q' is less than half of '%q'. Took %q and %q, respectively " , lrr .Command (), rr .Command (), lightElapsed , elapsed )
813
+ }
790
814
})
791
815
792
816
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" ))
817
+ // helper function to run command then, return target profile object from json output.
818
+ extractProfileObjFunc := func (rr * RunResult ) * config.Profile {
819
+ var jsonObject map [string ][]config.Profile
820
+ err := json .Unmarshal (rr .Stdout .Bytes (), & jsonObject )
821
+ if err != nil {
822
+ t .Errorf ("failed to decode json from profile list: args %q: %v" , rr .Command (), err )
823
+ return nil
824
+ }
825
+
826
+ for _ , profileObject := range jsonObject ["valid" ] {
827
+ if profileObject .Name == profile {
828
+ return & profileObject
829
+ }
830
+ }
831
+ return nil
832
+ }
833
+
834
+ start := time .Now ()
835
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" ))
836
+ elapsed := time .Since (start )
795
837
if err != nil {
796
838
t .Errorf ("failed to list profiles with json format. args %q: %v" , rr .Command (), err )
797
839
}
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 )
840
+ t .Logf ("Took %q to run %q" , elapsed , rr .Command ())
841
+
842
+ pr := extractProfileObjFunc (rr )
843
+ if pr == nil {
844
+ t .Errorf ("expected the json of 'profile list' to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
802
845
}
803
- validProfiles := jsonObject ["valid" ]
804
- profileExists := false
805
- for _ , profileObject := range validProfiles {
806
- if profileObject ["Name" ] == profile {
807
- profileExists = true
808
- break
809
- }
846
+
847
+ start = time .Now ()
848
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" , "--light" ))
849
+ lightElapsed := time .Since (start )
850
+ if err != nil {
851
+ t .Errorf ("failed to list profiles with json format. args %q: %v" , lrr .Command (), err )
810
852
}
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 ())
853
+ t .Logf ("Took %q to run %q" , lightElapsed , lrr .Command ())
854
+
855
+ pr = extractProfileObjFunc (lrr )
856
+ if pr == nil || pr .Status != "Skipped" {
857
+ 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
858
}
814
859
860
+ if elapsed < (lightElapsed * 2 ) {
861
+ t .Errorf ("expected running time of '%q' is less than half of '%q'. Took %q and %q, respectively " , lrr .Command (), rr .Command (), lightElapsed , elapsed )
862
+ }
815
863
})
816
864
}
817
865
0 commit comments