Skip to content

Commit

Permalink
Update Landscape tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Jan 23, 2024
1 parent 6e901ea commit 7f6e2fd
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions windows-agent/internal/proservices/landscape/landscape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/canonical/ubuntu-pro-for-windows/common/testutils"
"github.com/canonical/ubuntu-pro-for-windows/common/wsltestutils"
"github.com/canonical/ubuntu-pro-for-windows/mocks/landscape/landscapemockservice"
"github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/cloudinit"
"github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/config"
"github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/database"
"github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/distro"
Expand Down Expand Up @@ -161,7 +162,10 @@ func TestConnect(t *testing.T) {
_, err = db.GetDistroAndUpdateProperties(ctx, distroName, distro.Properties{})
require.NoError(t, err, "Setup: GetDistroAndUpdateProperties should return no errors")

service, err := landscape.New(conf, db)
cinit, err := cloudinit.New(ctx, conf, t.TempDir())
require.NoError(t, err, "Setup: cloud init shoud return no errors")

service, err := landscape.New(conf, db, cinit)
require.NoError(t, err, "Setup: NewClient should return no errrors")

ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -272,7 +276,10 @@ func TestSendUpdatedInfo(t *testing.T) {

const hostname = "HOSTNAME"

service, err := landscape.New(conf, db, landscape.WithHostname(hostname))
cinit, err := cloudinit.New(ctx, conf, t.TempDir())
require.NoError(t, err, "Setup: cloud init shoud return no errors")

service, err := landscape.New(conf, db, cinit, landscape.WithHostname(hostname))
require.NoError(t, err, "Landscape NewClient should not return an error")

ctl := service.Controller()
Expand Down Expand Up @@ -449,7 +456,10 @@ func TestAutoReconnection(t *testing.T) {

const hostname = "HOSTNAME"

service, err := landscape.New(conf, db, landscape.WithHostname(hostname))
cinit, err := cloudinit.New(ctx, conf, t.TempDir())
require.NoError(t, err, "Setup: cloud init shoud return no errors")

service, err := landscape.New(conf, db, cinit, landscape.WithHostname(hostname))
require.NoError(t, err, "Landscape NewClient should not return an error")
defer service.Stop(ctx)

Expand Down Expand Up @@ -641,7 +651,10 @@ func TestReceiveCommands(t *testing.T) {
require.NoError(t, d.LockAwake(), "Setup: could not lock distro awake")
}

clientService, err := landscape.New(conf, db, landscape.WithHostname("HOSTNAME"))
cinit, err := cloudinit.New(ctx, conf, t.TempDir())
require.NoError(t, err, "Setup: cloud init shoud return no errors")

clientService, err := landscape.New(conf, db, cinit, landscape.WithHostname("HOSTNAME"))
require.NoError(t, err, "Landscape NewClient should not return an error")

err = clientService.Connect(ctx)
Expand Down Expand Up @@ -789,6 +802,8 @@ func requireCommandResult(t *testing.T, ctx context.Context, command command, di
require.False(t, ok, "Distro unexpectedly reached state %q", wsl.Stopped)
}
case cmdInstall:
require.Fail(t, "TODO: Test cloud-init file was created")

inst := isAppxInstalled(t, testAppx)

d := wsl.NewDistro(ctx, testDistroAppx)
Expand All @@ -807,6 +822,8 @@ func requireCommandResult(t *testing.T, ctx context.Context, command command, di
require.True(t, reg, "Distro should not have been registered")
}
case cmdUninstall:
require.Fail(t, "TODO: Test cloud-init file was removed")

inst := isAppxInstalled(t, testAppx)
if wantSuccess {
require.False(t, inst, "Appx should no longer be installed, but it is")
Expand Down Expand Up @@ -912,6 +929,8 @@ type mockConfig struct {
landscapeUIDErr bool
setLandscapeUIDErr bool

notifications []func()

mu sync.Mutex
}

Expand Down Expand Up @@ -960,6 +979,14 @@ func (m *mockConfig) SetLandscapeAgentUID(ctx context.Context, uid string) error
return errors.New("Mock error")
}

for _, f := range m.notifications {
f()
}

m.landscapeAgentUID = uid
return nil
}

func (m *mockConfig) Notify(f func()) {
m.notifications = append(m.notifications, f)
}

0 comments on commit 7f6e2fd

Please sign in to comment.