Skip to content

Commit 663cc10

Browse files
authored
chore(tests): adding tests to the host preflights logic (#2302)
* chore(tests): adding integration tests to the host preflights logic * chore(tests): create preflight interface and fix the preflight integration tests * chore(tests): add tests to the whole manager piece too * chore: cleanup mocks * chore(tests): fix flaky test * chore: trying to make CI happy * chore: rename * chore: rename file * chore: finally make the linter happy
1 parent 0a97e0a commit 663cc10

File tree

19 files changed

+1740
-94
lines changed

19 files changed

+1740
-94
lines changed

api/controllers/install/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
171171
preflight.WithRuntimeConfig(controller.rc),
172172
preflight.WithLogger(controller.logger),
173173
preflight.WithMetricsReporter(controller.metricsReporter),
174-
preflight.WithHostPreflight(controller.install.Steps.HostPreflight),
174+
preflight.WithHostPreflightStore(preflight.NewMemoryStore(controller.install.Steps.HostPreflight)),
175175
)
176176
}
177177

api/integration/auth_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/replicatedhq/embedded-cluster/api/controllers/install"
1515
"github.com/replicatedhq/embedded-cluster/api/internal/managers/installation"
1616
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
17+
"github.com/replicatedhq/embedded-cluster/api/pkg/utils"
1718
"github.com/replicatedhq/embedded-cluster/api/types"
1819
"github.com/stretchr/testify/assert"
1920
"github.com/stretchr/testify/require"
@@ -29,7 +30,7 @@ func TestAuthLoginAndTokenValidation(t *testing.T) {
2930
// Create an install controller
3031
installController, err := install.NewInstallController(
3132
install.WithInstallationManager(installation.NewInstallationManager(
32-
installation.WithNetUtils(&mockNetUtils{ifaces: []string{"eth0", "eth1"}}),
33+
installation.WithNetUtils(&utils.MockNetUtils{}),
3334
)),
3435
)
3536
require.NoError(t, err)

api/integration/console_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package integration
22

33
import (
44
"encoding/json"
5-
"errors"
65
"net/http"
76
"net/http/httptest"
87
"testing"
@@ -11,17 +10,19 @@ import (
1110
"github.com/replicatedhq/embedded-cluster/api"
1211
"github.com/replicatedhq/embedded-cluster/api/controllers/console"
1312
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
13+
"github.com/replicatedhq/embedded-cluster/api/pkg/utils"
1414
"github.com/replicatedhq/embedded-cluster/api/types"
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
1717
)
1818

1919
func TestConsoleListAvailableNetworkInterfaces(t *testing.T) {
20-
netutils := &mockNetUtils{ifaces: []string{"eth0", "eth1"}}
20+
netUtils := &utils.MockNetUtils{}
21+
netUtils.On("ListValidNetworkInterfaces").Return([]string{"eth0", "eth1"}, nil).Once()
2122

2223
// Create a console controller
2324
consoleController, err := console.NewConsoleController(
24-
console.WithNetUtils(netutils),
25+
console.WithNetUtils(netUtils),
2526
)
2627
require.NoError(t, err)
2728

@@ -62,11 +63,12 @@ func TestConsoleListAvailableNetworkInterfaces(t *testing.T) {
6263
}
6364

6465
func TestConsoleListAvailableNetworkInterfacesUnauthorized(t *testing.T) {
65-
netutils := &mockNetUtils{ifaces: []string{"eth0", "eth1"}}
66+
netUtils := &utils.MockNetUtils{}
67+
netUtils.On("ListValidNetworkInterfaces").Return([]string{"eth0", "eth1"}, nil).Once()
6668

6769
// Create a console controller
6870
consoleController, err := console.NewConsoleController(
69-
console.WithNetUtils(netutils),
71+
console.WithNetUtils(netUtils),
7072
)
7173
require.NoError(t, err)
7274

@@ -103,11 +105,12 @@ func TestConsoleListAvailableNetworkInterfacesUnauthorized(t *testing.T) {
103105

104106
func TestConsoleListAvailableNetworkInterfacesError(t *testing.T) {
105107
// Create a mock that returns an error
106-
netutils := &mockNetUtils{err: errors.New("failed to list network interfaces")}
108+
netUtils := &utils.MockNetUtils{}
109+
netUtils.On("ListValidNetworkInterfaces").Return(nil, assert.AnError).Once()
107110

108111
// Create a console controller
109112
consoleController, err := console.NewConsoleController(
110-
console.WithNetUtils(netutils),
113+
console.WithNetUtils(netUtils),
111114
)
112115
require.NoError(t, err)
113116

0 commit comments

Comments
 (0)