Update testing helpers to use factory
This commit is contained in:
parent
2c35229013
commit
2c756b3c07
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user