diff --git a/windows-agent/internal/config/config.go b/windows-agent/internal/config/config.go index dd7fe2dd3..9d4de3c4d 100644 --- a/windows-agent/internal/config/config.go +++ b/windows-agent/internal/config/config.go @@ -65,29 +65,6 @@ func (c *Config) Subscription(ctx context.Context) (token string, source Source, return token, source, nil } -// ProvisioningTasks returns a slice of all tasks to be submitted upon first contact with a distro. -func (c *Config) ProvisioningTasks(ctx context.Context, distroName string) ([]task.Task, error) { - var taskList []task.Task - - // Refresh data from registry - c.mu.Lock() - defer c.mu.Unlock() - - if err := c.load(); err != nil { - return nil, fmt.Errorf("could not load: %v", err) - } - - // Ubuntu Pro attachment - proToken, _ := c.subscription.resolve() - taskList = append(taskList, tasks.ProAttachment{Token: proToken}) - - // Landscape config - lconf, _ := c.landscape.resolve() - taskList = append(taskList, tasks.LandscapeConfigure{Config: lconf, HostagentUID: c.landscape.UID}) - - return taskList, nil -} - // LandscapeClientConfig returns the value of the landscape server URL and // the method it was acquired with (if any). func (c *Config) LandscapeClientConfig(ctx context.Context) (string, Source, error) { diff --git a/windows-agent/internal/config/config_test.go b/windows-agent/internal/config/config_test.go index 689537bc3..ede61daa1 100644 --- a/windows-agent/internal/config/config_test.go +++ b/windows-agent/internal/config/config_test.go @@ -14,8 +14,6 @@ import ( config "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/config" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/contracts" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/database" - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/task" - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/tasks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" wsl "github.com/ubuntu/gowsl" @@ -84,7 +82,7 @@ func TestSubscription(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakFile) @@ -140,7 +138,7 @@ func TestLandscapeConfig(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakFile) @@ -190,7 +188,7 @@ func TestLandscapeAgentUID(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakFile) @@ -221,63 +219,6 @@ func TestLandscapeAgentUID(t *testing.T) { } } -func TestProvisioningTasks(t *testing.T) { - if wsl.MockAvailable() { - t.Parallel() - } - - testCases := map[string]struct { - settingsState settingsState - - wantToken string - wantLandscapeConf string - wantLandscapeUID string - - wantError bool - }{ - "Success when there is no data": {settingsState: untouched}, - "Success when there is an empty config file": {settingsState: fileExists}, - "Success when the file's pro token field exists but is empty": {settingsState: userTokenExists}, - "Success with a user token": {settingsState: userTokenHasValue, wantToken: "user_token"}, - "Success when there is Landscape config": {settingsState: userLandscapeConfigHasValue | landscapeUIDHasValue, wantLandscapeConf: "[client]\nuser=JohnDoe", wantLandscapeUID: "landscapeUID1234"}, - } - - for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { - ctx := context.Background() - if wsl.MockAvailable() { - t.Parallel() - ctx = wsl.WithMock(ctx, wslmock.New()) - } - - db, err := database.New(ctx, t.TempDir(), nil) - require.NoError(t, err, "Setup: could not create empty database") - - setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, false) - conf := config.New(ctx, dir) - setup(t, conf) - - gotTasks, err := conf.ProvisioningTasks(ctx, "UBUNTU") - if tc.wantError { - require.Error(t, err, "ProvisioningTasks should return an error") - return - } - require.NoError(t, err, "ProvisioningTasks should return no error") - - wantTasks := []task.Task{ - tasks.ProAttachment{Token: tc.wantToken}, - tasks.LandscapeConfigure{ - Config: tc.wantLandscapeConf, - HostagentUID: tc.wantLandscapeUID, - }, - } - - require.ElementsMatch(t, wantTasks, gotTasks, "Unexpected contents returned by ProvisioningTasks") - }) - } -} - func TestSetUserSubscription(t *testing.T) { if wsl.MockAvailable() { t.Parallel() @@ -307,7 +248,7 @@ func TestSetUserSubscription(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakFile) @@ -364,7 +305,7 @@ func TestSetLandscapeAgentUID(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakFile) @@ -437,7 +378,7 @@ func TestFetchMicrosoftStoreSubscription(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") setup, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakConfigFile) @@ -542,7 +483,7 @@ func TestUpdateRegistryData(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") _, dir := setUpMockSettings(t, ctx, db, tc.settingsState, tc.breakConfigFile) @@ -645,7 +586,7 @@ func TestNotify(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty database") _, dir := setUpMockSettings(t, ctx, db, untouched, false) diff --git a/windows-agent/internal/distros/database/database.go b/windows-agent/internal/distros/database/database.go index 34d5e1b91..5ab594116 100644 --- a/windows-agent/internal/distros/database/database.go +++ b/windows-agent/internal/distros/database/database.go @@ -16,7 +16,6 @@ import ( "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/consts" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/distro" - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/worker" log "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/grpc/logstreamer" "gopkg.in/yaml.v3" ) @@ -34,8 +33,7 @@ type DistroDB struct { scheduleTrigger chan struct{} - storageDir string - provisioning worker.Provisioning + storageDir string ctx context.Context cancelCtx func() @@ -57,7 +55,7 @@ type DistroDB struct { // Every certain amount of times, the database wil purge all distros that // are no longer registered or that have been marked as unreachable. This // cleanup can be triggered on demmand with TriggerCleanup. -func New(ctx context.Context, storageDir string, provisioning worker.Provisioning) (*DistroDB, error) { +func New(ctx context.Context, storageDir string) (*DistroDB, error) { if err := os.MkdirAll(storageDir, 0600); err != nil { return nil, fmt.Errorf("could not create database directory: %w", err) } @@ -73,7 +71,6 @@ func New(ctx context.Context, storageDir string, provisioning worker.Provisionin db := &DistroDB{ storageDir: storageDir, scheduleTrigger: make(chan struct{}), - provisioning: provisioning, ctx: ctx, cancelCtx: cancel, } @@ -151,7 +148,7 @@ func (db *DistroDB) GetDistroAndUpdateProperties(ctx context.Context, name strin if !found { log.Debugf(ctx, "Cache miss, creating %q and adding it to the database", name) - d, err := distro.New(db.ctx, name, props, db.storageDir, &db.distroStartMu, distro.WithProvisioning(db.provisioning)) + d, err := distro.New(db.ctx, name, props, db.storageDir, &db.distroStartMu) if err != nil { return nil, err } @@ -169,7 +166,7 @@ func (db *DistroDB) GetDistroAndUpdateProperties(ctx context.Context, name strin go d.Cleanup(ctx) delete(db.distros, normalizedName) - d, err := distro.New(db.ctx, name, props, db.storageDir, &db.distroStartMu, distro.WithProvisioning(db.provisioning)) + d, err := distro.New(db.ctx, name, props, db.storageDir, &db.distroStartMu) if err != nil { return nil, err } diff --git a/windows-agent/internal/distros/database/database_test.go b/windows-agent/internal/distros/database/database_test.go index 03228b38b..69c214e68 100644 --- a/windows-agent/internal/distros/database/database_test.go +++ b/windows-agent/internal/distros/database/database_test.go @@ -80,7 +80,7 @@ func TestNew(t *testing.T) { databaseFromTemplate(t, dbDir, distroID{distro, guid}) } - db, err := database.New(ctx, dbDir, nil) + db, err := database.New(ctx, dbDir) if err == nil { defer db.Close(ctx) } @@ -123,7 +123,7 @@ func TestDatabaseGetAll(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: database creation should not fail") defer db.Close(ctx) @@ -166,7 +166,7 @@ func TestDatabaseGet(t *testing.T) { distroID{registeredDistroInDB, registeredGUID}, distroID{nonRegisteredDistroInDB, oldGUID}) - db, err := database.New(ctx, databaseDir, nil) + db, err := database.New(ctx, databaseDir) require.NoError(t, err, "Setup: New() should return no error") // Must use Cleanup. If we use defer, it'll run before the subtests are launched. @@ -212,7 +212,7 @@ func TestDatabaseGetAfterClose(t *testing.T) { ctx = wsl.WithMock(ctx, wslmock.New()) } - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: New() should return no error") db.Close(ctx) @@ -260,7 +260,7 @@ func TestDatabaseDump(t *testing.T) { databaseFromTemplate(t, dbDir, distroID{distro1, guid1}, distroID{distro2, guid2}) } - db, err := database.New(ctx, dbDir, nil) + db, err := database.New(ctx, dbDir) require.NoError(t, err, "Setup: empty database should be created without issue") defer db.Close(ctx) @@ -408,7 +408,7 @@ func TestGetDistroAndUpdateProperties(t *testing.T) { distroID{distroInDB, guids[distroInDB]}, distroID{reRegisteredDistro, guids[reRegisteredDistro]}) - db, err := database.New(ctx, dbDir, nil) + db, err := database.New(ctx, dbDir) require.NoError(t, err, "Setup: New() should return no error") defer db.Close(ctx) @@ -510,7 +510,7 @@ func TestDatabaseCleanup(t *testing.T) { databaseFromTemplate(t, dbDir, distros...) - db, err := database.New(ctx, dbDir, nil) + db, err := database.New(ctx, dbDir) require.NoError(t, err, "Setup: New() should have returned no error") defer db.Close(ctx) diff --git a/windows-agent/internal/distros/distro/distro.go b/windows-agent/internal/distros/distro/distro.go index d8c16d336..e70cfa7db 100644 --- a/windows-agent/internal/distros/distro/distro.go +++ b/windows-agent/internal/distros/distro/distro.go @@ -59,9 +59,8 @@ func (*NotValidError) Error() string { type options struct { guid uuid.UUID - provisioning worker.Provisioning taskProcessingContext context.Context - newWorkerFunc func(context.Context, *Distro, string, worker.Provisioning) (workerInterface, error) + newWorkerFunc func(context.Context, *Distro, string) (workerInterface, error) } // Option is an optional argument for distro.New. @@ -75,14 +74,6 @@ func WithGUID(guid uuid.UUID) Option { } } -// WithProvisioning allows for providing a worker.Provisioning. If that is done, -// it'll be queried for the provisioning tasks and these will be submitted. -func WithProvisioning(c worker.Provisioning) Option { - return func(o *options) { - o.provisioning = c - } -} - // New creates a new Distro object after searching for a distro with the given name. // // - If identity.Name is not registered, a DistroDoesNotExist error is returned. @@ -99,8 +90,8 @@ func New(ctx context.Context, name string, props Properties, storageDir string, opts := options{ guid: nilGUID, taskProcessingContext: context.Background(), - newWorkerFunc: func(ctx context.Context, d *Distro, dir string, provisioning worker.Provisioning) (workerInterface, error) { - return worker.New(ctx, d, dir, worker.WithProvisioning(provisioning)) + newWorkerFunc: func(ctx context.Context, d *Distro, dir string) (workerInterface, error) { + return worker.New(ctx, d, dir) }, } @@ -147,7 +138,7 @@ func New(ctx context.Context, name string, props Properties, storageDir string, return nil, err } - distro.worker, err = opts.newWorkerFunc(opts.taskProcessingContext, distro, storageDir, opts.provisioning) + distro.worker, err = opts.newWorkerFunc(opts.taskProcessingContext, distro, storageDir) if err != nil { return nil, err } diff --git a/windows-agent/internal/distros/distro/distro_test.go b/windows-agent/internal/distros/distro/distro_test.go index 80ed3524b..ccf18d515 100644 --- a/windows-agent/internal/distros/distro/distro_test.go +++ b/windows-agent/internal/distros/distro/distro_test.go @@ -12,7 +12,6 @@ import ( "github.com/canonical/ubuntu-pro-for-windows/common/wsltestutils" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/distro" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/task" - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/worker" "github.com/canonical/ubuntu-pro-for-windows/wslserviceapi" "github.com/google/uuid" log "github.com/sirupsen/logrus" @@ -71,15 +70,13 @@ func TestNew(t *testing.T) { distro string withGUID string preventWorkDirCreation bool - withProvisioning bool nilMutex bool wantErr bool wantErrType error }{ - "Success with a registered distro": {distro: registeredDistro}, - "Success with a registered distro and its GUID": {distro: registeredDistro, withGUID: registeredGUID}, - "Success with a registered distro with provisioning": {distro: registeredDistro, withProvisioning: true}, + "Success with a registered distro": {distro: registeredDistro}, + "Success with a registered distro and its GUID": {distro: registeredDistro, withGUID: registeredGUID}, // Error cases "Error when workdir cannot be created": {distro: registeredDistro, preventWorkDirCreation: true, wantErr: true}, @@ -104,10 +101,6 @@ func TestNew(t *testing.T) { args = append(args, distro.WithGUID(GUID)) } - if tc.withProvisioning { - args = append(args, distro.WithProvisioning(&mockProvisioning{})) - } - workDir := t.TempDir() if tc.preventWorkDirCreation { workDir = filepath.Join(workDir, "workdir") @@ -575,7 +568,6 @@ func TestWorkerConstruction(t *testing.T) { withMockWorker, worker := mockWorkerInjector(tc.constructorReturnErr) workDir := t.TempDir() - provisioning := mockProvisioning{} d, err := distro.New(ctx, distroName, @@ -583,7 +575,6 @@ func TestWorkerConstruction(t *testing.T) { workDir, startupMutex(), distro.WithTaskProcessingContext(ctx), - distro.WithProvisioning(provisioning), withMockWorker) defer d.Cleanup(context.Background()) @@ -597,7 +588,6 @@ func TestWorkerConstruction(t *testing.T) { require.NotNil(t, (*worker).newCtx.Value(testContextMarker(42)), "Worker's constructor should be called with the distro's context or a child of it") require.Equal(t, d, (*worker).newDistro, "Worker's constructor should be called with the distro it is attached to") require.Equal(t, workDir, (*worker).newDir, "Worker's constructor should be called with the same workdir as the distro's") - require.Equal(t, provisioning, (*worker).newProvisioning, "Worker's constructor should be called with the config passed to the distro") }) } } @@ -790,10 +780,9 @@ func TestUninstall(t *testing.T) { } type mockWorker struct { - newCtx context.Context - newDistro *distro.Distro - newDir string - newProvisioning worker.Provisioning + newCtx context.Context + newDistro *distro.Distro + newDir string isActiveCalled bool clientCalled bool @@ -804,12 +793,11 @@ type mockWorker struct { func mockWorkerInjector(constructorReturnsError bool) (distro.Option, **mockWorker) { mock := new(*mockWorker) - newMockWorker := func(ctx context.Context, d *distro.Distro, tmpDir string, conf worker.Provisioning) (distro.Worker, error) { + newMockWorker := func(ctx context.Context, d *distro.Distro, tmpDir string) (distro.Worker, error) { w := &mockWorker{ - newCtx: ctx, - newDistro: d, - newDir: tmpDir, - newProvisioning: conf, + newCtx: ctx, + newDistro: d, + newDir: tmpDir, } *mock = w if constructorReturnsError { @@ -851,9 +839,3 @@ func (w *mockWorker) EnqueueDeferredTasks() { func (w *mockWorker) Stop(context.Context) { w.stopCalled = true } - -type mockProvisioning struct{} - -func (c mockProvisioning) ProvisioningTasks(ctx context.Context, distroName string) ([]task.Task, error) { - return nil, nil -} diff --git a/windows-agent/internal/distros/distro/export_test.go b/windows-agent/internal/distros/distro/export_test.go index 246136c7d..958367235 100644 --- a/windows-agent/internal/distros/distro/export_test.go +++ b/windows-agent/internal/distros/distro/export_test.go @@ -2,8 +2,6 @@ package distro import ( "context" - - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/worker" ) func WithTaskProcessingContext(ctx context.Context) Option { @@ -16,7 +14,7 @@ func WithTaskProcessingContext(ctx context.Context) Option { // WithNewWorker is an optional parameter for distro.New that allows for overriding // the worker.New constructor. It is meant for dependency injection. -func WithNewWorker(newWorkerFunc func(context.Context, *Distro, string, worker.Provisioning) (workerInterface, error)) Option { +func WithNewWorker(newWorkerFunc func(context.Context, *Distro, string) (workerInterface, error)) Option { return func(o *options) { o.newWorkerFunc = newWorkerFunc } diff --git a/windows-agent/internal/distros/worker/worker.go b/windows-agent/internal/distros/worker/worker.go index 15a0fe0c7..3399b2024 100644 --- a/windows-agent/internal/distros/worker/worker.go +++ b/windows-agent/internal/distros/worker/worker.go @@ -38,35 +38,10 @@ type Worker struct { connMu sync.RWMutex } -// Provisioning is an interface which provides provisioning tasks. -type Provisioning interface { - ProvisioningTasks(context.Context, string) ([]task.Task, error) -} - -type options struct { - provisioning Provisioning -} - -// Option is an optional argument for worker.New. -type Option func(*options) - -// WithProvisioning is an optional parameter for worker.New that allows for -// conditionally importing the provisioning tasks. -func WithProvisioning(provisioning Provisioning) Option { - return func(o *options) { - o.provisioning = provisioning - } -} - // New creates a new worker and starts it. Call Stop when you're done to avoid leaking the task execution goroutine. -func New(ctx context.Context, d distro, storageDir string, args ...Option) (*Worker, error) { +func New(ctx context.Context, d distro, storageDir string) (*Worker, error) { storagePath := filepath.Join(storageDir, d.Name()+".tasks") - var opts options - for _, f := range args { - f(&opts) - } - tm, err := newTaskManager(storagePath) if err != nil { return nil, err @@ -79,21 +54,6 @@ func New(ctx context.Context, d distro, storageDir string, args ...Option) (*Wor w.start(ctx) - // load and submit provisioning tasks. (case of first contact with distro) - if opts.provisioning == nil { - return w, nil - } - - provisioning, err := opts.provisioning.ProvisioningTasks(ctx, d.Name()) - if err != nil { - return w, err - } - - if err := w.SubmitTasks(provisioning...); err != nil { - w.Stop(ctx) - return nil, err - } - return w, nil } diff --git a/windows-agent/internal/distros/worker/worker_test.go b/windows-agent/internal/distros/worker/worker_test.go index cda281880..134fe0cd6 100644 --- a/windows-agent/internal/distros/worker/worker_test.go +++ b/windows-agent/internal/distros/worker/worker_test.go @@ -60,10 +60,6 @@ func TestNew(t *testing.T) { taskFile taskFileState fillUpQueue bool - withProvisioning bool - emptyProvisioning bool - provisioningTasksErr bool - wantErr bool wantNTasks int }{ @@ -72,14 +68,10 @@ func TestNew(t *testing.T) { "Success with task file containing a single task": {taskFile: fileHasOneTask, wantNTasks: 1}, "Success with task file containing multiple tasks": {taskFile: fileHasTwoTasks, wantNTasks: 2}, - "Success with empty provisioning": {withProvisioning: true, emptyProvisioning: true}, - "Success with single-task provisioning": {withProvisioning: true, wantNTasks: 1}, - // Error "Error when task file reads non-registered task type": {taskFile: fileHasNonRegisteredTask, wantErr: true}, "Error when task file has bad syntax": {taskFile: fileHasBadSyntax, wantErr: true}, "Error when task file is unreadable": {taskFile: fileIsDir, wantErr: true}, - "Error when ProvisioningTasks fails": {withProvisioning: true, provisioningTasksErr: true, wantErr: true}, } for name, tc := range testCases { @@ -120,20 +112,11 @@ func TestNew(t *testing.T) { require.NoError(t, err, "Setup: could not make a directory in task file's location") } - var args []worker.Option - if tc.withProvisioning { - c := &mockProvisioning{ - provisioningTasksErr: tc.provisioningTasksErr, - privisioningTasksReturnsNil: tc.emptyProvisioning, - } - args = append(args, worker.WithProvisioning(c)) - } - // We pass a cancelled context so that no tasks are popped // and we can accurately assert on the task queue length. cancel() - w, err := worker.New(ctx, distro, distroDir, args...) + w, err := worker.New(ctx, distro, distroDir) if err == nil { defer w.Stop(ctx) } @@ -889,18 +872,3 @@ func taskfileFromTemplate[T task.Task](t *testing.T) []byte { return w.Bytes() } - -type mockProvisioning struct { - provisioningTasksErr bool - privisioningTasksReturnsNil bool -} - -func (c mockProvisioning) ProvisioningTasks(ctx context.Context, distroName string) ([]task.Task, error) { - if c.provisioningTasksErr { - return nil, errors.New("mock error") - } - if c.privisioningTasksReturnsNil { - return nil, nil - } - return []task.Task{&testTask{}}, nil -} diff --git a/windows-agent/internal/proservices/landscape/executor_test.go b/windows-agent/internal/proservices/landscape/executor_test.go index 33cae1630..ee7e737e7 100644 --- a/windows-agent/internal/proservices/landscape/executor_test.go +++ b/windows-agent/internal/proservices/landscape/executor_test.go @@ -491,7 +491,7 @@ func testReceiveCommand(t *testing.T, distrosettings distroSettings, testSetup f } } - db, err := database.New(ctx, t.TempDir(), tb.conf) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: database New should not return an error") tb.db = db diff --git a/windows-agent/internal/proservices/landscape/landscape_test.go b/windows-agent/internal/proservices/landscape/landscape_test.go index 7468b1c11..8c2df8e94 100644 --- a/windows-agent/internal/proservices/landscape/landscape_test.go +++ b/windows-agent/internal/proservices/landscape/landscape_test.go @@ -24,7 +24,6 @@ import ( "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" - "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/distros/task" "github.com/canonical/ubuntu-pro-for-windows/windows-agent/internal/proservices/landscape" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -154,7 +153,7 @@ func TestConnect(t *testing.T) { defer server.Stop() } - db, err := database.New(ctx, t.TempDir(), conf) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: database New should not return an error") distroName, _ := wsltestutils.RegisterDistro(t, ctx, true) @@ -257,7 +256,7 @@ func TestSendUpdatedInfo(t *testing.T) { go server.Serve(lis) defer server.Stop() - db, err := database.New(ctx, t.TempDir(), conf) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: database New should not return an error") distroName, _ := wsltestutils.RegisterDistro(t, ctx, true) @@ -448,7 +447,7 @@ func TestAutoReconnection(t *testing.T) { landscapeClientConfig: executeLandscapeConfigTemplate(t, defaultLandscapeConfig, "", lis.Addr()), } - db, err := database.New(ctx, t.TempDir(), conf) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: database New should not return an error") const hostname = "HOSTNAME" @@ -651,10 +650,6 @@ func (m *mockConfig) LandscapeClientConfig(ctx context.Context) (string, config. return m.landscapeClientConfig, config.SourceUser, nil } -func (m *mockConfig) ProvisioningTasks(ctx context.Context, distroName string) ([]task.Task, error) { - return nil, nil -} - func (m *mockConfig) Subscription(ctx context.Context) (string, config.Source, error) { m.mu.Lock() defer m.mu.Unlock() diff --git a/windows-agent/internal/proservices/proservices.go b/windows-agent/internal/proservices/proservices.go index 088639d9d..9c047c632 100644 --- a/windows-agent/internal/proservices/proservices.go +++ b/windows-agent/internal/proservices/proservices.go @@ -75,7 +75,7 @@ func New(ctx context.Context, publicDir, privateDir string, args ...Option) (s M return s, err } - db, err := database.New(ctx, privateDir, conf) + db, err := database.New(ctx, privateDir) if err != nil { return s, err } diff --git a/windows-agent/internal/proservices/registrywatcher/watcher_test.go b/windows-agent/internal/proservices/registrywatcher/watcher_test.go index 685a37bf7..375a2b034 100644 --- a/windows-agent/internal/proservices/registrywatcher/watcher_test.go +++ b/windows-agent/internal/proservices/registrywatcher/watcher_test.go @@ -55,7 +55,7 @@ func TestRegistryWatcher(t *testing.T) { conf := &mockConfig{} - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: could not create empty DB") var startingProToken, startingLandscapeConfig string diff --git a/windows-agent/internal/proservices/ui/ui_test.go b/windows-agent/internal/proservices/ui/ui_test.go index 7014090ea..45f4b616b 100644 --- a/windows-agent/internal/proservices/ui/ui_test.go +++ b/windows-agent/internal/proservices/ui/ui_test.go @@ -25,7 +25,7 @@ func TestNew(t *testing.T) { t.Parallel() dir := t.TempDir() - db, err := database.New(ctx, dir, nil) + db, err := database.New(ctx, dir) require.NoError(t, err, "Setup: empty database New() should return no error") defer db.Close(ctx) @@ -69,7 +69,7 @@ func TestAttachPro(t *testing.T) { t.Parallel() dir := t.TempDir() - db, err := database.New(ctx, dir, nil) + db, err := database.New(ctx, dir) require.NoError(t, err, "Setup: empty database New() should return no error") defer db.Close(ctx) @@ -150,7 +150,7 @@ func TestGetSubscriptionInfo(t *testing.T) { ctx := context.Background() dir := t.TempDir() - db, err := database.New(ctx, dir, nil) + db, err := database.New(ctx, dir) require.NoError(t, err, "Setup: empty database New() should return no error") service := ui.New(ctx, &tc.config, db) @@ -192,7 +192,7 @@ func TestNotifyPurchase(t *testing.T) { ctx := context.Background() dir := t.TempDir() - db, err := database.New(ctx, dir, nil) + db, err := database.New(ctx, dir) require.NoError(t, err, "Setup: empty database New() should return no error") service := ui.New(ctx, &tc.config, db) diff --git a/windows-agent/internal/proservices/wslinstance/wslinstance_test.go b/windows-agent/internal/proservices/wslinstance/wslinstance_test.go index f64439a9b..1622e9cbb 100644 --- a/windows-agent/internal/proservices/wslinstance/wslinstance_test.go +++ b/windows-agent/internal/proservices/wslinstance/wslinstance_test.go @@ -39,7 +39,7 @@ func TestNew(t *testing.T) { t.Parallel() ctx := context.Background() - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: empty database New() should return no error") defer db.Close(ctx) @@ -149,7 +149,7 @@ func TestConnected(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := database.New(ctx, t.TempDir(), nil) + db, err := database.New(ctx, t.TempDir()) require.NoError(t, err, "Setup: empty database New() should return no error") defer db.Close(ctx)