@@ -1245,8 +1245,8 @@ func getCacheDir(caller string, name string) (string, error) {
12451245 return cacheDir , nil
12461246}
12471247
1248- // FindComponentsDir identifies the directory that holds the components .
1249- func FindComponentsDir (dir , version string ) (string , error ) {
1248+ // findAgentDataVersionDir identifies the directory that holds the agent data of the given version .
1249+ func findAgentDataVersionDir (dir , version string ) (string , error ) {
12501250 dataDir := filepath .Join (dir , "data" )
12511251 agentVersions , err := os .ReadDir (dataDir )
12521252 if err != nil {
@@ -1256,6 +1256,7 @@ func FindComponentsDir(dir, version string) (string, error) {
12561256 for _ , fi := range agentVersions {
12571257 filename := fi .Name ()
12581258 if strings .HasPrefix (filename , "elastic-agent-" ) && fi .IsDir () {
1259+ // Below we exclude the hash suffix (7 characters) of the directory to check the version
12591260 if version != "" && filename [:len (filename )- 7 ] != "elastic-agent-" + version {
12601261 // version specified but version mismatch. in case of upgrade we have multiple
12611262 // directories, we don't want first found
@@ -1268,14 +1269,44 @@ func FindComponentsDir(dir, version string) (string, error) {
12681269 if versionDir == "" {
12691270 return "" , fmt .Errorf ("failed to find versioned directory for version %q" , version )
12701271 }
1271- componentsDir := filepath .Join (dataDir , versionDir , "components" )
1272+ return filepath .Join (dataDir , versionDir ), nil
1273+ }
1274+
1275+ // FindComponentsDir identifies the directory that holds the components.
1276+ func FindComponentsDir (dir , version string ) (string , error ) {
1277+ versionDir , err := findAgentDataVersionDir (dir , version )
1278+ if err != nil {
1279+ return "" , err
1280+ }
1281+ componentsDir := filepath .Join (versionDir , "components" )
12721282 fi , err := os .Stat (componentsDir )
12731283 if (err != nil && ! os .IsExist (err )) || ! fi .IsDir () {
12741284 return "" , fmt .Errorf ("failed to find components directory at %s: %w" , componentsDir , err )
12751285 }
12761286 return componentsDir , nil
12771287}
12781288
1289+ // FindRunDir identifies the directory that holds the run folder.
1290+ func FindRunDir (fixture * Fixture ) (string , error ) {
1291+ agentWorkDir := fixture .WorkDir ()
1292+ if pf := fixture .PackageFormat (); pf == "deb" || pf == "rpm" {
1293+ // these are hardcoded paths in packages.yml
1294+ agentWorkDir = "/var/lib/elastic-agent"
1295+ }
1296+
1297+ version := fixture .Version ()
1298+ versionDir , err := findAgentDataVersionDir (agentWorkDir , version )
1299+ if err != nil {
1300+ return "" , err
1301+ }
1302+ runDir := filepath .Join (versionDir , "run" )
1303+ fi , err := os .Stat (runDir )
1304+ if (err != nil && ! os .IsExist (err )) || ! fi .IsDir () {
1305+ return "" , fmt .Errorf ("failed to find run directory at %s: %w" , runDir , err )
1306+ }
1307+ return runDir , nil
1308+ }
1309+
12791310// writeSpecFile writes the specification to a specification file at the defined destination.
12801311func writeSpecFile (dest string , spec * component.Spec ) error {
12811312 data , err := yaml .Marshal (spec )
0 commit comments