-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement(5832): added integration tests
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/cmd" | ||
atesting "github.com/elastic/elastic-agent/pkg/testing" | ||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRestrictUpgradeDeb(t *testing.T) { | ||
define.Require(t, define.Requirements{ | ||
Group: Deb, | ||
Stack: &define.Stack{}, | ||
Sudo: true, | ||
OS: []define.OS{ | ||
{ | ||
Type: define.Linux, | ||
Distro: "ubuntu", | ||
}, | ||
}, | ||
}) | ||
t.Run("when agent is deployed via deb, a user should not be able to upgrade the agent using the cli", func(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("deb")) | ||
require.NoError(t, err) | ||
installOpts := atesting.InstallOpts{ | ||
NonInteractive: true, | ||
Privileged: true, | ||
Force: true, | ||
} | ||
|
||
_, err = fixture.InstallWithoutEnroll(ctx, &installOpts) | ||
require.NoError(t, err) | ||
|
||
require.Eventuallyf(t, func() bool { | ||
err = fixture.IsHealthy(ctx) | ||
return err == nil | ||
}, 5*time.Minute, time.Second, | ||
"Elastic-Agent did not report healthy. Agent status error: \"%v\"", | ||
err, | ||
) | ||
|
||
out, err := fixture.Exec(ctx, []string{"upgrade", "1.0.0"}) | ||
require.Error(t, err) | ||
require.Contains(t, string(out), cmd.UpgradeDisabledError.Error()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/cmd" | ||
atesting "github.com/elastic/elastic-agent/pkg/testing" | ||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRestrictUpgradeRPM(t *testing.T) { | ||
define.Require(t, define.Requirements{ | ||
Group: RPM, | ||
Stack: &define.Stack{}, | ||
Sudo: true, | ||
OS: []define.OS{ | ||
{ | ||
Type: define.Linux, | ||
Distro: "rhel", | ||
}, | ||
}, | ||
}) | ||
t.Run("when agent is deployed via rpm, a user should not be able to upgrade the agent using the cli", func(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("rpm")) | ||
require.NoError(t, err) | ||
installOpts := atesting.InstallOpts{ | ||
NonInteractive: true, | ||
Privileged: true, | ||
Force: true, | ||
} | ||
|
||
_, err = fixture.InstallWithoutEnroll(ctx, &installOpts) | ||
require.NoError(t, err) | ||
|
||
require.Eventuallyf(t, func() bool { | ||
err = fixture.IsHealthy(ctx) | ||
return err == nil | ||
}, 5*time.Minute, time.Second, | ||
"Elastic-Agent did not report healthy. Agent status error: \"%v\"", | ||
err, | ||
) | ||
|
||
out, err := fixture.Exec(ctx, []string{"upgrade", "1.0.0"}) | ||
require.Error(t, err) | ||
require.Contains(t, string(out), cmd.UpgradeDisabledError.Error()) | ||
}) | ||
} |