@@ -721,16 +721,40 @@ func TestEndpointLogsAreCollectedInDiagnostics(t *testing.T) {
721
721
"Endpoint component or units are not healthy." ,
722
722
)
723
723
724
+ // get endpoint component name
725
+ endpointComponents := getEndpointComponents (ctx , t , fixture .Client ())
726
+ require .NotEmpty (t , endpointComponents , "there should be at least one endpoint component" )
727
+
728
+ t .Logf ("endpoint components: %v" , endpointComponents )
729
+
724
730
outDir := t .TempDir ()
725
731
diagFile := t .Name () + ".zip"
726
732
diagAbsPath := filepath .Join (outDir , diagFile )
727
733
_ , err = fixture .Exec (ctx , []string {"diagnostics" , "-f" , diagAbsPath })
728
734
require .NoError (t , err , "diagnostics command failed" )
729
735
require .FileExists (t , diagAbsPath , "diagnostic archive should have been created" )
730
- checkDiagnosticsForEndpointFiles (t , diagAbsPath )
736
+ checkDiagnosticsForEndpointFiles (t , diagAbsPath , endpointComponents )
731
737
}
732
738
733
- func checkDiagnosticsForEndpointFiles (t * testing.T , diagsPath string ) {
739
+ func getEndpointComponents (ctx context.Context , t * testing.T , c client.Client ) []string {
740
+
741
+ err := c .Connect (ctx )
742
+ require .NoError (t , err , "connecting to agent to retrieve endpoint components" )
743
+ defer c .Disconnect ()
744
+
745
+ agentState , err := c .State (ctx )
746
+ require .NoError (t , err , "retrieving agent state" )
747
+
748
+ var endpointComponents []string
749
+ for _ , componentState := range agentState .Components {
750
+ if strings .Contains (componentState .Name , "endpoint" ) {
751
+ endpointComponents = append (endpointComponents , componentState .ID )
752
+ }
753
+ }
754
+ return endpointComponents
755
+ }
756
+
757
+ func checkDiagnosticsForEndpointFiles (t * testing.T , diagsPath string , endpointComponents []string ) {
734
758
zipReader , err := zip .OpenReader (diagsPath )
735
759
require .NoError (t , err , "error opening diagnostics archive" )
736
760
@@ -745,20 +769,22 @@ func checkDiagnosticsForEndpointFiles(t *testing.T, diagsPath string) {
745
769
}
746
770
t .Logf ("---- End contents of diagnostics archive" )
747
771
// check there are files under the components/ directory
748
- endpointComponentDirName := "components/endpoint-default"
749
- endpointComponentDir , err := zipReader .Open (endpointComponentDirName )
750
- if assert .NoErrorf (t , err , "error looking up directory %q in diagnostic archive: %v" , endpointComponentDirName , err ) {
751
- defer func (endpointComponentDir fs.File ) {
752
- err := endpointComponentDir .Close ()
753
- if err != nil {
754
- assert .NoError (t , err , "error closing endpoint component directory" )
772
+ for _ , componentName := range endpointComponents {
773
+ endpointComponentDirName := fmt .Sprintf ("components/%s" , componentName )
774
+ endpointComponentDir , err := zipReader .Open (endpointComponentDirName )
775
+ if assert .NoErrorf (t , err , "error looking up directory %q for endpoint component %q in diagnostic archive: %v" , endpointComponentDirName , componentName , err ) {
776
+ defer func (endpointComponentDir fs.File ) {
777
+ err := endpointComponentDir .Close ()
778
+ if err != nil {
779
+ assert .NoError (t , err , "error closing endpoint component directory" )
780
+ }
781
+ }(endpointComponentDir )
782
+ if assert .Implementsf (t , (* fs .ReadDirFile )(nil ), endpointComponentDir , "endpoint component %q should have a directory in the diagnostic archive under %s" , componentName , endpointComponentDirName ) {
783
+ dirFile := endpointComponentDir .(fs.ReadDirFile )
784
+ endpointFiles , err := dirFile .ReadDir (- 1 )
785
+ assert .NoErrorf (t , err , "error reading endpoint component %q directory %q in diagnostic archive" , componentName , endpointComponentDirName )
786
+ assert .NotEmptyf (t , endpointFiles , "endpoint component %q directory should not be empty" , componentName )
755
787
}
756
- }(endpointComponentDir )
757
- if assert .Implementsf (t , (* fs .ReadDirFile )(nil ), endpointComponentDir , "endpoint should have a directory in the diagnostic archive under %s" , endpointComponentDirName ) {
758
- dirFile := endpointComponentDir .(fs.ReadDirFile )
759
- endpointFiles , err := dirFile .ReadDir (- 1 )
760
- assert .NoError (t , err , "error reading endpoint component directory %q in diagnostic archive" , endpointComponentDirName )
761
- assert .NotEmpty (t , endpointFiles , "endpoint component directory should not be empty" )
762
788
}
763
789
}
764
790
0 commit comments