Skip to content

Conversation

@jsoriano
Copy link
Member

@jsoriano jsoriano commented Apr 9, 2024

Use go-resource to define the state expected by the asset test runner.

The idea would be to apply this model also to the system test runner, to try to reduce its complexity.

With this architecture, each runner would have a resources method, that generate the expected resources based on some given parameters. On this example the only parameter would be whether the package must be installed or not. Then test runners would apply these resources before running the tests or on tear down stages.

"github.com/elastic/elastic-package/internal/packages/installer"
)

type FleetPackage struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct allows us to isolate the logic for the state of a package. It knows how to get the current state and update to the desired one. Having it as an independent object allows to test the logic more easily.

if err != nil {
return result.WithError(fmt.Errorf("cannot get installed package %q", manifest.Name, err))
}
installedAssets := installedPackage.Assets()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On apply we were already getting the assets. We wouldn't need this if go-resource had support to get info from defined resources.

@jsoriano jsoriano self-assigned this Apr 9, 2024
@jsoriano jsoriano requested a review from mrodm April 9, 2024 15:27
@jsoriano jsoriano marked this pull request as ready for review April 11, 2024 09:50
@jsoriano
Copy link
Member Author

Opening for review as it seems to work mostly as before. @mrodm wdyt of this approach?

I like that tear down gets the state from the system itself and doesn't need to keep track of what has been set up or not. But maybe this is complex in the system runner scenario. I also like that we can test each resource and its lifecycle more easily.

@mrodm
Copy link
Contributor

mrodm commented Apr 11, 2024

Opening for review as it seems to work mostly as before. @mrodm wdyt of this approach?

I like that tear down gets the state from the system itself and doesn't need to keep track of what has been set up or not. But maybe this is complex in the system runner scenario. I also like that we can test each resource and its lifecycle more easily.

It looks great this approach!
Easier to manage the conditions when to install/uninstall each resource (in this case Packages) and being able to add tests easily! Nice !!

Let's see if this can be applied easily also in system tests 🤞

r.deletePackageHandler = nil
resourcesOptions := resourcesOptions{
// Keep it installed only if we were running setup, or tests only.
installedPackage: r.options.RunSetup || r.options.RunTestsOnly,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

logger.Debug("Installing package...")
resourcesOptions := resourcesOptions{
// Install it unless we are running the tear down only.
installedPackage: !r.options.RunTearDown,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jsoriano
Copy link
Member Author

/test

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @jsoriano

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really promising, thanks! 🚀

@jsoriano jsoriano merged commit 052cfc8 into elastic:main Apr 16, 2024
@jsoriano jsoriano deleted the fleet-package-resources branch April 16, 2024 17:03
jsoriano added a commit that referenced this pull request May 16, 2024
Add go-resource resources for Fleet Policies, what will allow to continue the refactors in test runners, in line with #1756. It also allows to define specific integration tests for policies management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants