@@ -811,50 +811,98 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
811
811
})
812
812
813
813
t .Run ("profile_list" , func (t * testing.T ) {
814
+ // helper function to run command then, return target profile line from table output.
815
+ extractrofileListFunc := func (rr * RunResult ) string {
816
+ listLines := strings .Split (strings .TrimSpace (rr .Stdout .String ()), "\n " )
817
+ for i := 3 ; i < (len (listLines ) - 1 ); i ++ {
818
+ profileLine := listLines [i ]
819
+ if strings .Contains (profileLine , profile ) {
820
+ return profileLine
821
+ }
822
+ }
823
+ return ""
824
+ }
825
+
814
826
// List profiles
827
+ start := time .Now ()
815
828
rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" ))
829
+ elapsed := time .Since (start )
816
830
if err != nil {
817
831
t .Errorf ("failed to list profiles: args %q : %v" , rr .Command (), err )
818
832
}
833
+ t .Logf ("Took %q to run %q" , elapsed , rr .Command ())
819
834
820
- // Table output
821
- listLines := strings .Split (strings .TrimSpace (rr .Stdout .String ()), "\n " )
822
- profileExists := false
823
- for i := 3 ; i < (len (listLines ) - 1 ); i ++ {
824
- profileLine := listLines [i ]
825
- if strings .Contains (profileLine , profile ) {
826
- profileExists = true
827
- break
828
- }
829
- }
830
- if ! profileExists {
835
+ profileLine := extractrofileListFunc (rr )
836
+ if profileLine == "" {
831
837
t .Errorf ("expected 'profile list' output to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
832
838
}
839
+
840
+ // List profiles with light option.
841
+ start = time .Now ()
842
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-l" ))
843
+ lightElapsed := time .Since (start )
844
+ if err != nil {
845
+ t .Errorf ("failed to list profiles: args %q : %v" , lrr .Command (), err )
846
+ }
847
+ t .Logf ("Took %q to run %q" , lightElapsed , lrr .Command ())
848
+
849
+ profileLine = extractrofileListFunc (lrr )
850
+ if profileLine == "" || ! strings .Contains (profileLine , "Skipped" ) {
851
+ t .Errorf ("expected 'profile list' output to include %q with 'Skipped' status but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
852
+ }
853
+
854
+ if lightElapsed > 3 * time .Second {
855
+ t .Errorf ("expected running time of '%q' is less than 3 seconds. Took %q " , lrr .Command (), lightElapsed )
856
+ }
833
857
})
834
858
835
859
t .Run ("profile_json_output" , func (t * testing.T ) {
836
- // Json output
837
- rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "--output" , "json" ))
860
+ // helper function to run command then, return target profile object from json output.
861
+ extractProfileObjFunc := func (rr * RunResult ) * config.Profile {
862
+ var jsonObject map [string ][]config.Profile
863
+ err := json .Unmarshal (rr .Stdout .Bytes (), & jsonObject )
864
+ if err != nil {
865
+ t .Errorf ("failed to decode json from profile list: args %q: %v" , rr .Command (), err )
866
+ return nil
867
+ }
868
+
869
+ for _ , profileObject := range jsonObject ["valid" ] {
870
+ if profileObject .Name == profile {
871
+ return & profileObject
872
+ }
873
+ }
874
+ return nil
875
+ }
876
+
877
+ start := time .Now ()
878
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" ))
879
+ elapsed := time .Since (start )
838
880
if err != nil {
839
881
t .Errorf ("failed to list profiles with json format. args %q: %v" , rr .Command (), err )
840
882
}
841
- var jsonObject map [string ][]map [string ]interface {}
842
- err = json .Unmarshal (rr .Stdout .Bytes (), & jsonObject )
843
- if err != nil {
844
- t .Errorf ("failed to decode json from profile list: args %q: %v" , rr .Command (), err )
883
+ t .Logf ("Took %q to run %q" , elapsed , rr .Command ())
884
+
885
+ pr := extractProfileObjFunc (rr )
886
+ if pr == nil {
887
+ t .Errorf ("expected the json of 'profile list' to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
845
888
}
846
- validProfiles := jsonObject ["valid" ]
847
- profileExists := false
848
- for _ , profileObject := range validProfiles {
849
- if profileObject ["Name" ] == profile {
850
- profileExists = true
851
- break
852
- }
889
+
890
+ start = time .Now ()
891
+ lrr , err := Run (t , exec .CommandContext (ctx , Target (), "profile" , "list" , "-o" , "json" , "--light" ))
892
+ lightElapsed := time .Since (start )
893
+ if err != nil {
894
+ t .Errorf ("failed to list profiles with json format. args %q: %v" , lrr .Command (), err )
853
895
}
854
- if ! profileExists {
855
- t .Errorf ("expected the json of 'profile list' to include %q but got *%q*. args: %q" , profile , rr .Stdout .String (), rr .Command ())
896
+ t .Logf ("Took %q to run %q" , lightElapsed , lrr .Command ())
897
+
898
+ pr = extractProfileObjFunc (lrr )
899
+ if pr == nil || pr .Status != "Skipped" {
900
+ 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 ())
856
901
}
857
902
903
+ if lightElapsed > 3 * time .Second {
904
+ t .Errorf ("expected running time of '%q' is less than 3 seconds. Took %q " , lrr .Command (), lightElapsed )
905
+ }
858
906
})
859
907
}
860
908
0 commit comments