Skip to content

Commit

Permalink
enhancement(5832): added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanyalti committed Dec 16, 2024
1 parent 83a12c2 commit a1df208
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
54 changes: 54 additions & 0 deletions testing/integration/restrict_upgrade_deb_test.go
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())
})
}
54 changes: 54 additions & 0 deletions testing/integration/restrict_upgrade_rpm_test.go
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())
})
}

0 comments on commit a1df208

Please sign in to comment.