From 2c756b3c077ba297262e10c60cd3615706b60e2a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 7 Jul 2022 11:04:26 -0700 Subject: [PATCH] Update testing helpers to use factory --- internal/core/testing_basis.go | 21 +++++++++++++-- internal/core/testing_project.go | 27 ++++++++++---------- internal/core/testing_target.go | 44 +++++++++++++++++--------------- 3 files changed, 56 insertions(+), 36 deletions(-) diff --git a/internal/core/testing_basis.go b/internal/core/testing_basis.go index e7593e54b..c124f1210 100644 --- a/internal/core/testing_basis.go +++ b/internal/core/testing_basis.go @@ -6,10 +6,12 @@ import ( "os" "path/filepath" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/vagrant-plugin-sdk/core" coremocks "github.com/hashicorp/vagrant-plugin-sdk/core/mocks" "github.com/hashicorp/vagrant-plugin-sdk/datadir" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" + "github.com/hashicorp/vagrant-plugin-sdk/terminal" "github.com/hashicorp/vagrant/internal/plugin" "github.com/hashicorp/vagrant/internal/server/singleprocess" "github.com/mitchellh/go-testing-interface" @@ -109,12 +111,27 @@ func TestBasis(t testing.T, opts ...BasisOption) (b *Basis) { ), } + client := singleprocess.TestServer(t) + manager := plugin.TestManager(t) + + factory := NewFactory( + context.Background(), + client, + hclog.L(), + manager, + (terminal.UI)(nil), + ) + defaultOpts := []BasisOption{ - WithClient(singleprocess.TestServer(t)), + WithFactory(factory), + WithClient(client), WithBasisDataDir(projDir), WithBasisRef(&vagrant_plugin_sdk.Ref_Basis{Name: "test-basis"}), } - b, _ = NewBasis(context.Background(), append(defaultOpts, opts...)...) + b, err = factory.NewBasis("", append(defaultOpts, opts...)...) + if err != nil { + t.Fatal(err) + } return } diff --git a/internal/core/testing_project.go b/internal/core/testing_project.go index 4b3bd9a2c..0f31becdd 100644 --- a/internal/core/testing_project.go +++ b/internal/core/testing_project.go @@ -3,7 +3,7 @@ package core import ( "github.com/mitchellh/go-testing-interface" - "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" + // "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant/internal/plugin" ) @@ -12,12 +12,12 @@ import ( // factories, configuration, etc. func TestProject(t testing.T, opts ...BasisOption) *Project { b := TestBasis(t, opts...) - p, err := b.LoadProject([]ProjectOption{ - WithProjectRef(&vagrant_plugin_sdk.Ref_Project{ - Basis: b.Ref().(*vagrant_plugin_sdk.Ref_Basis), - Name: "test-project"}, - ), - }...) + p, err := b.factory.NewProject( + []ProjectOption{ + WithBasis(b), + WithProjectName("test-project"), + }..., + ) if err != nil { t.Fatal(err) @@ -31,13 +31,12 @@ func TestProject(t testing.T, opts ...BasisOption) *Project { func TestMinimalProject(t testing.T) *Project { pluginManager := plugin.TestManager(t) b := TestBasis(t, WithPluginManager(pluginManager)) - - p, err := b.LoadProject([]ProjectOption{ - WithProjectRef(&vagrant_plugin_sdk.Ref_Project{ - Basis: b.Ref().(*vagrant_plugin_sdk.Ref_Basis), - Name: "test-project"}, - ), - }...) + p, err := b.factory.NewProject( + []ProjectOption{ + WithBasis(b), + WithProjectName("test-project"), + }..., + ) if err != nil { t.Fatal(err) diff --git a/internal/core/testing_target.go b/internal/core/testing_target.go index 173104ffd..6b6c8f789 100644 --- a/internal/core/testing_target.go +++ b/internal/core/testing_target.go @@ -32,19 +32,19 @@ func TestTarget(t testing.T, p *Project, st *vagrant_server.Target, opts ...Test t.Fatal(err) } - target, err = p.LoadTarget([]TargetOption{ - WithTargetRef( - &vagrant_plugin_sdk.Ref_Target{ - Project: p.Ref().(*vagrant_plugin_sdk.Ref_Project), - Name: testingTarget.Name, - }, - ), - }...) - if err != nil { - t.Fatal(err) - } + target, err = p.factory.NewTarget( + []TargetOption{ + WithProject(p), + WithTargetRef( + &vagrant_plugin_sdk.Ref_Target{ + Project: p.Ref().(*vagrant_plugin_sdk.Ref_Project), + Name: testingTarget.Name, + }, + ), + }..., + ) - if err = p.refreshProject(); err != nil { + if err = p.Reload(); err != nil { t.Fatal(err) } @@ -78,14 +78,18 @@ func TestMinimalTarget(t testing.T) (target *Target) { t.Fatal(err) } - target, err = tp.LoadTarget([]TargetOption{ - WithTargetRef( - &vagrant_plugin_sdk.Ref_Target{ - Project: tp.Ref().(*vagrant_plugin_sdk.Ref_Project), - Name: "test-target", - }, - ), - }...) + target, err = tp.factory.NewTarget( + []TargetOption{ + WithProject(tp), + WithTargetRef( + &vagrant_plugin_sdk.Ref_Target{ + Project: tp.Ref().(*vagrant_plugin_sdk.Ref_Project), + Name: "test-target", + }, + ), + }..., + ) + if err != nil { t.Fatal(err) }