Remove ptypes and usages
This commit is contained in:
parent
6d88f3a54f
commit
a6d38a8795
@ -1,28 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
// import (
|
||||
// "github.com/imdario/mergo"
|
||||
// "github.com/mitchellh/go-testing-interface"
|
||||
// "github.com/stretchr/testify/require"
|
||||
|
||||
// pb "github.com/hashicorp/vagrant/internal/server/gen"
|
||||
// )
|
||||
|
||||
// // TestApplication returns a valid project for tests.
|
||||
// func TestApplication(t testing.T, src *pb.Machine) *pb.Machine {
|
||||
// t.Helper()
|
||||
|
||||
// if src == nil {
|
||||
// src = &pb.Machine{}
|
||||
// }
|
||||
|
||||
// require.NoError(t, mergo.Merge(src, &pb.Machine{
|
||||
// Project: &pb.Ref_Project{
|
||||
// Project: "test",
|
||||
// },
|
||||
|
||||
// Name: "test",
|
||||
// }))
|
||||
|
||||
// return src
|
||||
// }
|
||||
@ -1,97 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
// TestBasis returns a valid basis for tests.
|
||||
func TestBasis(t testing.T, src *vagrant_server.Basis) *vagrant_server.Basis {
|
||||
t.Helper()
|
||||
|
||||
if src == nil {
|
||||
src = &vagrant_server.Basis{}
|
||||
}
|
||||
|
||||
require.NoError(t, mergo.Merge(src, &vagrant_server.Basis{
|
||||
Name: "test",
|
||||
}))
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
// Type wrapper around the proto type so that we can add some methods.
|
||||
type Basis struct{ *vagrant_server.Basis }
|
||||
|
||||
// ProjectIdx returns the index of the project with the given resource id or -1 if its not found.
|
||||
func (b *Basis) ProjectIdx(n string) int {
|
||||
for i, project := range b.Projects {
|
||||
if project.ResourceId == n {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// Project returns the project with the given resource id. Returns nil if not found.
|
||||
func (b *Basis) Project(n string) *vagrant_plugin_sdk.Ref_Project {
|
||||
for _, project := range b.Projects {
|
||||
if project.ResourceId == n {
|
||||
return project
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Basis) AddProject(p *vagrant_server.Project) bool {
|
||||
return b.AddProjectRef(
|
||||
&vagrant_plugin_sdk.Ref_Project{
|
||||
Basis: p.Basis,
|
||||
Name: p.Name,
|
||||
ResourceId: p.ResourceId,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (b *Basis) AddProjectRef(p *vagrant_plugin_sdk.Ref_Project) bool {
|
||||
i := b.ProjectIdx(p.ResourceId)
|
||||
if i >= 0 {
|
||||
return false
|
||||
}
|
||||
b.Basis.Projects = append(b.Basis.Projects, p)
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *Basis) DeleteProject(p *vagrant_server.Project) bool {
|
||||
return b.DeleteProjectRef(
|
||||
&vagrant_plugin_sdk.Ref_Project{
|
||||
Basis: p.Basis,
|
||||
Name: p.Name,
|
||||
ResourceId: p.ResourceId,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (b *Basis) DeleteProjectRef(p *vagrant_plugin_sdk.Ref_Project) bool {
|
||||
i := b.ProjectIdx(p.ResourceId)
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
l := b.Basis.Projects
|
||||
l[len(l)-1], l[i] = l[i], l[len(l)-1]
|
||||
b.Basis.Projects = l
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateBasis validates the basis structure.
|
||||
func ValidateBasis(p *vagrant_server.Basis) error {
|
||||
return validation.ValidateStruct(p,
|
||||
validation.Field(&p.Name, validation.By(isEmpty)),
|
||||
)
|
||||
}
|
||||
@ -1,119 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
// import (
|
||||
// "time"
|
||||
|
||||
// "google.golang.org/protobuf/ptypes"
|
||||
// "github.com/imdario/mergo"
|
||||
// "github.com/mitchellh/go-testing-interface"
|
||||
// "github.com/stretchr/testify/require"
|
||||
|
||||
// pb "github.com/hashicorp/vagrant/internal/server/gen"
|
||||
// )
|
||||
|
||||
// // Type wrapper around the proto type so that we can add some methods.
|
||||
// type Component struct{ *pb.Component }
|
||||
|
||||
// // Match returns true if the component matches the given ref.
|
||||
// func (c *Component) Match(ref *pb.Ref_Component) bool {
|
||||
// if c == nil || ref == nil {
|
||||
// return false
|
||||
// }
|
||||
|
||||
// return c.Type == ref.Type && c.Name == ref.Name
|
||||
// }
|
||||
|
||||
// func TestValidBuild(t testing.T, src *pb.Build) *pb.Build {
|
||||
// t.Helper()
|
||||
|
||||
// if src == nil {
|
||||
// src = &pb.Build{}
|
||||
// }
|
||||
|
||||
// require.NoError(t, mergo.Merge(src, &pb.Build{
|
||||
// Application: &pb.Ref_Application{
|
||||
// Application: "a_test",
|
||||
// Project: "p_test",
|
||||
// },
|
||||
// Workspace: &pb.Ref_Workspace{
|
||||
// Workspace: "default",
|
||||
// },
|
||||
// Status: testStatus(t),
|
||||
// }))
|
||||
|
||||
// return src
|
||||
// }
|
||||
|
||||
// func TestValidArtifact(t testing.T, src *pb.PushedArtifact) *pb.PushedArtifact {
|
||||
// t.Helper()
|
||||
|
||||
// if src == nil {
|
||||
// src = &pb.PushedArtifact{}
|
||||
// }
|
||||
|
||||
// require.NoError(t, mergo.Merge(src, &pb.PushedArtifact{
|
||||
// Application: &pb.Ref_Application{
|
||||
// Application: "a_test",
|
||||
// Project: "p_test",
|
||||
// },
|
||||
// Workspace: &pb.Ref_Workspace{
|
||||
// Workspace: "default",
|
||||
// },
|
||||
// Status: testStatus(t),
|
||||
// }))
|
||||
|
||||
// return src
|
||||
// }
|
||||
|
||||
// func TestValidDeployment(t testing.T, src *pb.Deployment) *pb.Deployment {
|
||||
// t.Helper()
|
||||
|
||||
// if src == nil {
|
||||
// src = &pb.Deployment{}
|
||||
// }
|
||||
|
||||
// require.NoError(t, mergo.Merge(src, &pb.Deployment{
|
||||
// Application: &pb.Ref_Application{
|
||||
// Application: "a_test",
|
||||
// Project: "p_test",
|
||||
// },
|
||||
// Workspace: &pb.Ref_Workspace{
|
||||
// Workspace: "default",
|
||||
// },
|
||||
// Status: testStatus(t),
|
||||
// }))
|
||||
|
||||
// return src
|
||||
// }
|
||||
|
||||
// func TestValidRelease(t testing.T, src *pb.Release) *pb.Release {
|
||||
// t.Helper()
|
||||
|
||||
// if src == nil {
|
||||
// src = &pb.Release{}
|
||||
// }
|
||||
|
||||
// require.NoError(t, mergo.Merge(src, &pb.Release{
|
||||
// Application: &pb.Ref_Application{
|
||||
// Application: "a_test",
|
||||
// Project: "p_test",
|
||||
// },
|
||||
// Workspace: &pb.Ref_Workspace{
|
||||
// Workspace: "default",
|
||||
// },
|
||||
// Status: testStatus(t),
|
||||
// }))
|
||||
|
||||
// return src
|
||||
// }
|
||||
|
||||
// func testStatus(t testing.T) *pb.Status {
|
||||
// pt, err := ptypes.TimestampProto(time.Now())
|
||||
// require.NoError(t, err)
|
||||
|
||||
// return &pb.Status{
|
||||
// State: pb.Status_SUCCESS,
|
||||
// StartTime: pt,
|
||||
// CompleteTime: pt,
|
||||
// }
|
||||
// }
|
||||
@ -1,68 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
func TestJobNew(t testing.T, src *vagrant_server.Job) *vagrant_server.Job {
|
||||
t.Helper()
|
||||
|
||||
if src == nil {
|
||||
src = &vagrant_server.Job{}
|
||||
}
|
||||
|
||||
require.NoError(t, mergo.Merge(src, &vagrant_server.Job{
|
||||
Scope: &vagrant_server.Job_Target{
|
||||
Target: &vagrant_plugin_sdk.Ref_Target{
|
||||
ResourceId: "TESTMACH",
|
||||
Project: &vagrant_plugin_sdk.Ref_Project{
|
||||
ResourceId: "TESTPROJ",
|
||||
Basis: &vagrant_plugin_sdk.Ref_Basis{
|
||||
ResourceId: "TESTBAS",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TargetRunner: &vagrant_server.Ref_Runner{
|
||||
Target: &vagrant_server.Ref_Runner_Any{
|
||||
Any: &vagrant_server.Ref_RunnerAny{},
|
||||
},
|
||||
},
|
||||
DataSource: &vagrant_server.Job_DataSource{
|
||||
Source: &vagrant_server.Job_DataSource_Local{
|
||||
Local: &vagrant_server.Job_Local{},
|
||||
},
|
||||
},
|
||||
Operation: &vagrant_server.Job_Noop_{
|
||||
Noop: &vagrant_server.Job_Noop{},
|
||||
},
|
||||
}))
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
// ValidateJob validates the job structure.
|
||||
func ValidateJob(job *vagrant_server.Job) error {
|
||||
return validation.ValidateStruct(job,
|
||||
validation.Field(&job.Id, validation.By(isEmpty)),
|
||||
validation.Field(&job.TargetRunner, validation.Required),
|
||||
validation.Field(&job.Operation, validation.Required),
|
||||
)
|
||||
}
|
||||
|
||||
func isEmpty(v interface{}) error {
|
||||
if reflect.ValueOf(v).IsZero() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("must be empty")
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
func TestValidateJob(t *testing.T) {
|
||||
cases := []struct {
|
||||
Name string
|
||||
Modify func(*vagrant_server.Job)
|
||||
Error string
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
|
||||
{
|
||||
"id is set",
|
||||
func(j *vagrant_server.Job) { j.Id = "nope" },
|
||||
"id: must be empty",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.Name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
job := TestJobNew(t, nil)
|
||||
if f := tt.Modify; f != nil {
|
||||
f(job)
|
||||
}
|
||||
|
||||
err := ValidateJob(job)
|
||||
if tt.Error == "" {
|
||||
require.NoError(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.Error(err)
|
||||
require.Contains(err.Error(), tt.Error)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
// TestProject returns a valid project for tests.
|
||||
func TestProject(t testing.T, src *vagrant_server.Project) *vagrant_server.Project {
|
||||
t.Helper()
|
||||
|
||||
if src == nil {
|
||||
src = &vagrant_server.Project{}
|
||||
}
|
||||
|
||||
require.NoError(t, mergo.Merge(src, &vagrant_server.Project{
|
||||
Name: "test",
|
||||
Basis: &vagrant_plugin_sdk.Ref_Basis{},
|
||||
}))
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
// Type wrapper around the proto type so that we can add some methods.
|
||||
type Project struct{ *vagrant_server.Project }
|
||||
|
||||
// MachineIdx returns the index of the machine with the given resource id or -1 if its not found.
|
||||
func (p *Project) TargetIdx(n string) int {
|
||||
for i, target := range p.Targets {
|
||||
if target.ResourceId == n {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// Machine returns the machine with the given resource id. Returns nil if not found.
|
||||
func (p *Project) Target(n string) *vagrant_plugin_sdk.Ref_Target {
|
||||
for _, target := range p.Targets {
|
||||
if target.ResourceId == n {
|
||||
return target
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Project) AddTarget(m *vagrant_server.Target) bool {
|
||||
return p.AddTargetRef(
|
||||
&vagrant_plugin_sdk.Ref_Target{
|
||||
Project: m.Project,
|
||||
Name: m.Name,
|
||||
ResourceId: m.ResourceId,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (p *Project) AddTargetRef(m *vagrant_plugin_sdk.Ref_Target) bool {
|
||||
i := p.TargetIdx(m.ResourceId)
|
||||
if i >= 0 {
|
||||
return false
|
||||
}
|
||||
p.Project.Targets = append(p.Project.Targets, m)
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *Project) DeleteTarget(m *vagrant_server.Target) bool {
|
||||
return p.DeleteTargetRef(
|
||||
&vagrant_plugin_sdk.Ref_Target{
|
||||
Project: m.Project,
|
||||
Name: m.Name,
|
||||
ResourceId: m.ResourceId,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (p *Project) DeleteTargetRef(m *vagrant_plugin_sdk.Ref_Target) bool {
|
||||
i := p.TargetIdx(m.ResourceId)
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
ms := make([]*vagrant_plugin_sdk.Ref_Target, len(p.Project.Targets)-1)
|
||||
copy(ms[0:], p.Project.Targets[0:i])
|
||||
copy(ms[i:], p.Project.Targets[i+1:])
|
||||
p.Project.Targets = ms
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateProject validates the project structure.
|
||||
func ValidateProject(p *vagrant_server.Project) error {
|
||||
return validation.ValidateStruct(p,
|
||||
validation.Field(&p.Name, validation.By(isEmpty)),
|
||||
)
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
func TestRunner(t testing.T, src *vagrant_server.Runner) *vagrant_server.Runner {
|
||||
t.Helper()
|
||||
|
||||
if src == nil {
|
||||
src = &vagrant_server.Runner{}
|
||||
}
|
||||
|
||||
id, err := server.Id()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, mergo.Merge(src, &vagrant_server.Runner{
|
||||
Id: id,
|
||||
}))
|
||||
|
||||
return src
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
func TestValidateServerConfig(t *testing.T) {
|
||||
cases := []struct {
|
||||
Name string
|
||||
Modify func(*vagrant_server.ServerConfig)
|
||||
Error string
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
|
||||
{
|
||||
"no advertise addrs",
|
||||
func(c *vagrant_server.ServerConfig) { c.AdvertiseAddrs = nil },
|
||||
"advertise_addrs: cannot be blank",
|
||||
},
|
||||
|
||||
{
|
||||
"two advertise addrs",
|
||||
func(c *vagrant_server.ServerConfig) {
|
||||
c.AdvertiseAddrs = append(c.AdvertiseAddrs, nil)
|
||||
},
|
||||
"advertise_addrs: the length must be exactly 1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.Name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
cfg := TestServerConfig(t, nil)
|
||||
if f := tt.Modify; f != nil {
|
||||
f(cfg)
|
||||
}
|
||||
|
||||
err := ValidateServerConfig(cfg)
|
||||
if tt.Error == "" {
|
||||
require.NoError(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.Error(err)
|
||||
require.Contains(err.Error(), tt.Error)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package ptypes
|
||||
|
||||
import (
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
|
||||
// TestTarget returns a valid target for tests.
|
||||
func TestTarget(t testing.T, src *vagrant_server.Target) *vagrant_server.Target {
|
||||
t.Helper()
|
||||
|
||||
if src == nil {
|
||||
src = &vagrant_server.Target{}
|
||||
}
|
||||
|
||||
require.NoError(t, mergo.Merge(src, &vagrant_server.Target{
|
||||
Name: "test",
|
||||
Project: &vagrant_plugin_sdk.Ref_Project{},
|
||||
}))
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
// ValidateTarget validates the target structure.
|
||||
func ValidateTarget(t *vagrant_server.Target) error {
|
||||
return validation.ValidateStruct(t,
|
||||
validation.Field(&t.Name, validation.By(isEmpty)),
|
||||
)
|
||||
}
|
||||
@ -26,6 +26,7 @@ func TestServiceBasis(t *testing.T) {
|
||||
resp, err := client.UpsertBasis(ctx, &vagrant_server.UpsertBasisRequest{
|
||||
Basis: &vagrant_server.Basis{
|
||||
Name: "mybasis",
|
||||
Path: "/dev/null",
|
||||
},
|
||||
})
|
||||
require.NoError(err)
|
||||
@ -54,6 +55,7 @@ func TestServiceBasis(t *testing.T) {
|
||||
_, err = client.UpsertBasis(ctx, &vagrant_server.UpsertBasisRequest{
|
||||
Basis: &vagrant_server.Basis{
|
||||
Name: "mybasis",
|
||||
Path: "/dev/null",
|
||||
},
|
||||
})
|
||||
require.NoError(err)
|
||||
|
||||
@ -107,5 +107,6 @@ func testBox() *vagrant_server.Box {
|
||||
// Id must be Name-Provider-Version because indexing assumes it is
|
||||
// (the NewBox constructor normally generates this in core/box)
|
||||
ResourceId: "test/box-1.2.3-virtualbox",
|
||||
Directory: "/dev/null/box",
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,6 @@ import (
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
"github.com/hashicorp/vagrant/internal/server/logbuffer"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
serverptypes "github.com/hashicorp/vagrant/internal/server/ptypes"
|
||||
"github.com/hashicorp/vagrant/internal/server/singleprocess/state"
|
||||
)
|
||||
|
||||
@ -117,8 +116,8 @@ func (s *service) ValidateJob(
|
||||
var err error
|
||||
result := &vagrant_server.ValidateJobResponse{Valid: true}
|
||||
|
||||
// Struct validation
|
||||
if err := serverptypes.ValidateJob(req.Job); err != nil {
|
||||
// Validate the job details
|
||||
if err := s.state.JobValidate(req.Job); err != nil {
|
||||
result.Valid = false
|
||||
result.ValidationError = status.New(codes.FailedPrecondition, err.Error()).Proto()
|
||||
return result, nil
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
serverptypes "github.com/hashicorp/vagrant/internal/server/ptypes"
|
||||
)
|
||||
|
||||
func TestServiceQueueJob(t *testing.T) {
|
||||
@ -24,7 +23,7 @@ func TestServiceQueueJob(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Simplify writing tests
|
||||
type Req = vagrant_server.QueueJobRequest
|
||||
@ -34,7 +33,7 @@ func TestServiceQueueJob(t *testing.T) {
|
||||
|
||||
// Create, should get an ID back
|
||||
resp, err := client.QueueJob(ctx, &Req{
|
||||
Job: serverptypes.TestJobNew(t, nil),
|
||||
Job: TestJob(t, client, nil),
|
||||
})
|
||||
require.NoError(err)
|
||||
require.NotNil(resp)
|
||||
@ -51,7 +50,7 @@ func TestServiceQueueJob(t *testing.T) {
|
||||
|
||||
// Create, should get an ID back
|
||||
resp, err := client.QueueJob(ctx, &Req{
|
||||
Job: serverptypes.TestJobNew(t, nil),
|
||||
Job: TestJob(t, client, nil),
|
||||
ExpiresIn: "1ms",
|
||||
})
|
||||
require.NoError(err)
|
||||
@ -83,7 +82,7 @@ func TestServiceValidateJob(t *testing.T) {
|
||||
|
||||
// Create, should get an ID back
|
||||
resp, err := client.ValidateJob(ctx, &Req{
|
||||
Job: serverptypes.TestJobNew(t, nil),
|
||||
Job: TestJob(t, client, nil),
|
||||
})
|
||||
require.NoError(err)
|
||||
require.NotNil(resp)
|
||||
@ -95,7 +94,7 @@ func TestServiceValidateJob(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
// Create, should get an ID back
|
||||
job := serverptypes.TestJobNew(t, nil)
|
||||
job := TestJob(t, client, nil)
|
||||
job.Id = "HELLO"
|
||||
resp, err := client.ValidateJob(ctx, &Req{
|
||||
Job: job,
|
||||
@ -117,10 +116,14 @@ func TestServiceGetJobStream_complete(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil)})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
@ -243,10 +246,14 @@ func TestServiceGetJobStream_bufferedData(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil)})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
@ -318,7 +325,11 @@ func TestServiceGetJobStream_bufferedData(t *testing.T) {
|
||||
require.Equal(io.EOF, err)
|
||||
|
||||
// Get our job stream and verify we open
|
||||
stream, err := client.GetJobStream(ctx, &vagrant_server.GetJobStreamRequest{JobId: queueResp.JobId})
|
||||
stream, err := client.GetJobStream(ctx,
|
||||
&vagrant_server.GetJobStreamRequest{
|
||||
JobId: queueResp.JobId,
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
{
|
||||
resp, err := stream.Recv()
|
||||
@ -357,16 +368,25 @@ func TestServiceGetJobStream_expired(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil), ExpiresIn: "10ms"})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
ExpiresIn: "10ms",
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
|
||||
// Get our job stream and verify we open
|
||||
stream, err := client.GetJobStream(ctx, &vagrant_server.GetJobStreamRequest{JobId: queueResp.JobId})
|
||||
stream, err := client.GetJobStream(ctx,
|
||||
&vagrant_server.GetJobStreamRequest{
|
||||
JobId: queueResp.JobId,
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
|
||||
// Wait for completion
|
||||
|
||||
@ -115,7 +115,7 @@ func TestServiceProject(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.Error(err)
|
||||
require.Contains(err.Error(), "not found")
|
||||
require.Contains(err.Error(), "Basis: cannot be blank")
|
||||
})
|
||||
|
||||
t.Run("reasonable errors: get not found", func(t *testing.T) {
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
serverptypes "github.com/hashicorp/vagrant/internal/server/ptypes"
|
||||
)
|
||||
|
||||
// Complete happy path job stream
|
||||
@ -25,10 +24,14 @@ func TestServiceRunnerJobStream_complete(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, nil)
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil)})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
@ -73,7 +76,7 @@ func TestServiceRunnerJobStream_complete(t *testing.T) {
|
||||
// Should be done
|
||||
_, err = stream.Recv()
|
||||
require.Error(err)
|
||||
require.Equal(io.EOF, err)
|
||||
require.Equal(io.EOF.Error(), err.Error())
|
||||
|
||||
// Query our job and it should be done
|
||||
job, err := testServiceImpl(impl).state.JobById(queueResp.JobId, nil)
|
||||
@ -116,10 +119,14 @@ func TestServiceRunnerJobStream_errorBeforeAck(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil)})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
@ -178,10 +185,14 @@ func TestServiceRunnerJobStream_cancel(t *testing.T) {
|
||||
client := server.TestServer(t, impl)
|
||||
|
||||
// Initialize our basis
|
||||
TestBasis(t, client, serverptypes.TestBasis(t, nil))
|
||||
TestBasis(t, client, TestBasis(t, client, nil))
|
||||
|
||||
// Create a job
|
||||
queueResp, err := client.QueueJob(ctx, &vagrant_server.QueueJobRequest{Job: serverptypes.TestJobNew(t, nil)})
|
||||
queueResp, err := client.QueueJob(ctx,
|
||||
&vagrant_server.QueueJobRequest{
|
||||
Job: TestJob(t, client, nil),
|
||||
},
|
||||
)
|
||||
require.NoError(err)
|
||||
require.NotNil(queueResp)
|
||||
require.NotEmpty(queueResp.JobId)
|
||||
|
||||
@ -25,6 +25,7 @@ func TestServiceTarget(t *testing.T) {
|
||||
basisResp, err := client.UpsertBasis(ctx, &vagrant_server.UpsertBasisRequest{
|
||||
Basis: &vagrant_server.Basis{
|
||||
Name: "mybasis",
|
||||
Path: "/dev/null",
|
||||
},
|
||||
})
|
||||
require.NoError(err)
|
||||
@ -32,6 +33,7 @@ func TestServiceTarget(t *testing.T) {
|
||||
projectResp, err := client.UpsertProject(ctx, &vagrant_server.UpsertProjectRequest{
|
||||
Project: &vagrant_server.Project{
|
||||
Name: "myproject",
|
||||
Path: "/dev/null/project",
|
||||
Basis: &vagrant_plugin_sdk.Ref_Basis{ResourceId: basisResp.Basis.ResourceId},
|
||||
},
|
||||
})
|
||||
@ -60,6 +62,7 @@ func TestServiceTarget(t *testing.T) {
|
||||
basisResp, err := client.UpsertBasis(ctx, &vagrant_server.UpsertBasisRequest{
|
||||
Basis: &vagrant_server.Basis{
|
||||
Name: "mybasis",
|
||||
Path: "/dev/null",
|
||||
},
|
||||
})
|
||||
require.NoError(err)
|
||||
@ -122,6 +125,6 @@ func TestServiceTarget(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.Error(err)
|
||||
require.Contains(err.Error(), "not found")
|
||||
require.Contains(err.Error(), "not include parent")
|
||||
})
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
func TestBasis_Create(t *testing.T) {
|
||||
t.Run("Requires name and path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{})
|
||||
require.Error(result.Error)
|
||||
@ -20,7 +20,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{Path: "/dev/null"})
|
||||
require.Error(result.Error)
|
||||
@ -28,7 +28,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{Name: "default"})
|
||||
require.Error(result.Error)
|
||||
@ -36,7 +36,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Sets resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := Basis{Name: "default", Path: "/dev/null"}
|
||||
result := db.Save(&basis)
|
||||
@ -45,7 +45,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Retains resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE_ID"
|
||||
basis := Basis{Name: "default", Path: "/dev/null", ResourceId: rid}
|
||||
@ -55,7 +55,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{Name: "default", Path: "/dev/null"})
|
||||
require.NoError(result.Error)
|
||||
@ -65,7 +65,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{Name: "default", Path: "/dev/null"})
|
||||
require.NoError(result.Error)
|
||||
@ -75,7 +75,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate resource IDs", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE ID"
|
||||
result := db.Save(&Basis{Name: "default", Path: "/dev/null", ResourceId: rid})
|
||||
@ -86,7 +86,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Creates Vagrantfile when set", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vagrantfile := Vagrantfile{}
|
||||
basis := Basis{
|
||||
@ -103,7 +103,7 @@ func TestBasis_Create(t *testing.T) {
|
||||
|
||||
func TestBasis_Update(t *testing.T) {
|
||||
t.Run("Requires name and path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := &Basis{Name: "default", Path: "/dev/null"}
|
||||
result := db.Save(basis)
|
||||
@ -118,7 +118,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := &Basis{Name: "default", Path: "/dev/null"}
|
||||
result := db.Save(basis)
|
||||
@ -130,7 +130,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := &Basis{Name: "default", Path: "/dev/null"}
|
||||
result := db.Save(basis)
|
||||
@ -142,7 +142,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not update resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := Basis{Name: "default", Path: "/dev/null"}
|
||||
result := db.Save(&basis)
|
||||
@ -160,7 +160,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Adds Vagrantfile", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
basis := Basis{Name: "default", Path: "/dev/null"}
|
||||
@ -174,7 +174,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Updates existing Vagrantfile content", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
// Create inital basis
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
@ -210,7 +210,7 @@ func TestBasis_Update(t *testing.T) {
|
||||
|
||||
func TestBasis_Delete(t *testing.T) {
|
||||
t.Run("Deletes basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{Name: "default", Path: "/dev/null"})
|
||||
require.NoError(result.Error)
|
||||
@ -228,7 +228,7 @@ func TestBasis_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deletes Vagrantfile", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
result := db.Save(&Basis{
|
||||
@ -252,7 +252,7 @@ func TestBasis_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deletes Projects", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Basis{
|
||||
Name: "default",
|
||||
|
||||
@ -326,10 +326,10 @@ func (s *State) BoxFind(
|
||||
if b.Name == "" {
|
||||
return nil, lookupErrorToStatus("box", fmt.Errorf("no name given for box lookup"))
|
||||
}
|
||||
// If no provider is given, we error immediately
|
||||
if b.Provider == "" {
|
||||
return nil, lookupErrorToStatus("box", fmt.Errorf("no provider given for box lookup"))
|
||||
}
|
||||
// // If no provider is given, we error immediately
|
||||
// if b.Provider == "" {
|
||||
// return nil, lookupErrorToStatus("box", fmt.Errorf("no provider given for box lookup"))
|
||||
// }
|
||||
|
||||
// If the version is set to 0, mark it as default
|
||||
if b.Version == "0" {
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestBox_Create(t *testing.T) {
|
||||
t.Run("Requires directory, name, provider", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{})
|
||||
require.Error(result.Error)
|
||||
@ -20,7 +20,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires directory", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{Name: "default", Provider: "virt"})
|
||||
require.Error(result.Error)
|
||||
@ -28,7 +28,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{Provider: "virt", Directory: "/dev/null"})
|
||||
require.Error(result.Error)
|
||||
@ -36,7 +36,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires provider", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{Name: "default", Directory: "/dev/null"})
|
||||
require.Error(result.Error)
|
||||
@ -44,7 +44,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Sets the ResourceId", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -59,7 +59,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Defaults version when not set", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -74,7 +74,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Defaults version when set to 0", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -90,7 +90,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires version to be semver", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
box := &Box{
|
||||
Name: "default",
|
||||
@ -115,7 +115,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicates", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -138,7 +138,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Allows multiple versions", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -158,7 +158,7 @@ func TestBox_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Allows multiple providers", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Box{
|
||||
Name: "default",
|
||||
@ -390,7 +390,7 @@ func TestBox_State(t *testing.T) {
|
||||
b7, err := s.BoxFind(&vagrant_plugin_sdk.Ref_Box{
|
||||
Name: "dontexist",
|
||||
})
|
||||
require.Error(err)
|
||||
require.NoError(err)
|
||||
require.Nil(b7)
|
||||
|
||||
b8, err := s.BoxFind(&vagrant_plugin_sdk.Ref_Box{
|
||||
@ -415,7 +415,7 @@ func TestBox_State(t *testing.T) {
|
||||
Name: "hashicorp/bionic",
|
||||
Version: "< 1.0",
|
||||
})
|
||||
require.Error(err)
|
||||
require.NoError(err)
|
||||
require.Nil(b10)
|
||||
|
||||
b11, err := s.BoxFind(&vagrant_plugin_sdk.Ref_Box{
|
||||
|
||||
@ -15,7 +15,7 @@ func TestConfig(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.ConfigSet(&vagrant_server.ConfigVar{
|
||||
@ -73,7 +73,7 @@ func TestConfig(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.ConfigSet(
|
||||
@ -129,7 +129,7 @@ func TestConfig(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create a var
|
||||
require.NoError(s.ConfigSet(&vagrant_server.ConfigVar{
|
||||
@ -184,7 +184,7 @@ func TestConfig(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create the config
|
||||
require.NoError(s.ConfigSet(&vagrant_server.ConfigVar{
|
||||
@ -256,7 +256,7 @@ func TestConfig(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create the config
|
||||
require.NoError(s.ConfigSet(&vagrant_server.ConfigVar{
|
||||
@ -369,7 +369,7 @@ func TestConfigWatch(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
ws := memdb.NewWatchSet()
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ func TestSoftDecode(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
pref := testProjectProto(t, s)
|
||||
pref := TestProjectProto(t, s)
|
||||
tproto := &vagrant_server.Target{
|
||||
Project: pref,
|
||||
}
|
||||
|
||||
@ -8,12 +8,13 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/hashicorp/go-memdb"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
// "gorm.io/gorm/clause"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
"github.com/hashicorp/vagrant/internal/server/logbuffer"
|
||||
@ -123,7 +124,7 @@ func (i *InternalJob) AfterFind(tx *gorm.DB) (err error) {
|
||||
switch i.ScopeType {
|
||||
case "basis":
|
||||
var b Basis
|
||||
result := tx.Preload(clause.Associations).
|
||||
result := tx.
|
||||
First(&b, &Basis{Model: Model{ID: *i.ScopeID}})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
@ -131,7 +132,7 @@ func (i *InternalJob) AfterFind(tx *gorm.DB) (err error) {
|
||||
i.Scope = &b
|
||||
case "project":
|
||||
var p Project
|
||||
result := tx.Preload(clause.Associations).
|
||||
result := tx.
|
||||
First(&p, &Project{Model: Model{ID: *i.ScopeID}})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
@ -139,7 +140,7 @@ func (i *InternalJob) AfterFind(tx *gorm.DB) (err error) {
|
||||
i.Scope = &p
|
||||
case "target":
|
||||
var t Target
|
||||
result := tx.Preload(clause.Associations).
|
||||
result := tx.
|
||||
First(&t, &Target{Model: Model{ID: *i.ScopeID}})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
@ -152,6 +153,21 @@ func (i *InternalJob) AfterFind(tx *gorm.DB) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *InternalJob) Validate(tx *gorm.DB) error {
|
||||
return validation.ValidateStruct(i,
|
||||
validation.Field(&i.Jid,
|
||||
validation.Required,
|
||||
validation.By(
|
||||
checkUnique(
|
||||
tx.Model((*InternalJob)(nil)).
|
||||
Where(&InternalJob{Jid: i.Jid}).
|
||||
Not(&InternalJob{Model: Model{ID: i.ID}}),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Convert job to a protobuf message
|
||||
func (i *InternalJob) ToProto() *vagrant_server.Job {
|
||||
if i == nil {
|
||||
@ -310,6 +326,20 @@ type Job struct {
|
||||
Blocked bool
|
||||
}
|
||||
|
||||
func (s *State) JobValidate(jobpb *vagrant_server.Job) error {
|
||||
var job InternalJob
|
||||
|
||||
if err := s.softDecode(jobpb, &job); err != nil {
|
||||
return errorToStatus(err)
|
||||
}
|
||||
|
||||
if err := job.Validate(s.db); err != nil {
|
||||
return errorToStatus(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// JobCreate queues the given job.
|
||||
func (s *State) JobCreate(jobpb *vagrant_server.Job) error {
|
||||
txn := s.inmem.Txn(true)
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/go-memdb"
|
||||
// "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
serverptypes "github.com/hashicorp/vagrant/internal/server/ptypes"
|
||||
)
|
||||
|
||||
func TestJobAssign(t *testing.T) {
|
||||
@ -23,11 +22,11 @@ func TestJobAssign(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -59,11 +58,11 @@ func TestJobAssign(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -99,7 +98,7 @@ func TestJobAssign(t *testing.T) {
|
||||
}
|
||||
|
||||
// Insert another job
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "B",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -277,18 +276,18 @@ func TestJobAssign(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create two builds slightly apart
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
},
|
||||
})))
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "B",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -322,12 +321,12 @@ func TestJobAssign(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_B"})
|
||||
|
||||
// Create a build by ID
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -341,11 +340,11 @@ func TestJobAssign(t *testing.T) {
|
||||
},
|
||||
})))
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "B",
|
||||
})))
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "C",
|
||||
})))
|
||||
|
||||
@ -379,12 +378,12 @@ func TestJobAssign(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_B"})
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build by ID
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -425,13 +424,13 @@ func TestJobAssign(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
r := &vagrant_server.Runner{Id: "R_A", ByIdOnly: true}
|
||||
testRunnerProto(t, s, r)
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(serverptypes.TestJobNew(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -447,7 +446,7 @@ func TestJobAssign(t *testing.T) {
|
||||
require.Equal(ctx.Err(), err)
|
||||
|
||||
// Create a target
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "B",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -476,11 +475,11 @@ func TestJobAck(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -512,11 +511,11 @@ func TestJobAck(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -553,11 +552,11 @@ func TestJobAck(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -591,11 +590,11 @@ func TestJobComplete(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -632,11 +631,11 @@ func TestJobComplete(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -676,10 +675,10 @@ func TestJobIsAssignable(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create a build
|
||||
result, err := s.JobIsAssignable(ctx, testJobProto(t, &vagrant_server.Job{
|
||||
result, err := s.JobIsAssignable(ctx, TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -695,11 +694,11 @@ func TestJobIsAssignable(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Should be assignable
|
||||
result, err := s.JobIsAssignable(ctx, testJobProto(t, &vagrant_server.Job{
|
||||
result, err := s.JobIsAssignable(ctx, TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -720,11 +719,11 @@ func TestJobIsAssignable(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A", ByIdOnly: true})
|
||||
|
||||
// Should be assignable
|
||||
result, err := s.JobIsAssignable(ctx, testJobProto(t, &vagrant_server.Job{
|
||||
result, err := s.JobIsAssignable(ctx, TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -745,11 +744,11 @@ func TestJobIsAssignable(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_B"})
|
||||
|
||||
// Should be assignable
|
||||
result, err := s.JobIsAssignable(ctx, testJobProto(t, &vagrant_server.Job{
|
||||
result, err := s.JobIsAssignable(ctx, TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -772,11 +771,11 @@ func TestJobIsAssignable(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Should be assignable
|
||||
result, err := s.JobIsAssignable(ctx, testJobProto(t, &vagrant_server.Job{
|
||||
result, err := s.JobIsAssignable(ctx, TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -800,10 +799,10 @@ func TestJobCancel(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -826,11 +825,11 @@ func TestJobCancel(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -859,11 +858,11 @@ func TestJobCancel(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -892,11 +891,11 @@ func TestJobCancel(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -921,7 +920,7 @@ func TestJobCancel(t *testing.T) {
|
||||
require.NotEmpty(job.CancelTime)
|
||||
|
||||
// Create a another job
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "B",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -945,11 +944,11 @@ func TestJobCancel(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -987,7 +986,7 @@ func TestJobHeartbeat(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Set a short timeout
|
||||
@ -996,7 +995,7 @@ func TestJobHeartbeat(t *testing.T) {
|
||||
jobHeartbeatTimeout = 5 * time.Millisecond
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -1035,11 +1034,11 @@ func TestJobHeartbeat(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -1104,11 +1103,11 @@ func TestJobHeartbeat(t *testing.T) {
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
|
||||
projRef := testProjectProto(t, s)
|
||||
projRef := TestProjectProto(t, s)
|
||||
testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// Create a build
|
||||
require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
Id: "A",
|
||||
Scope: &vagrant_server.Job_Project{
|
||||
Project: projRef,
|
||||
@ -1184,11 +1183,11 @@ func TestJobHeartbeat(t *testing.T) {
|
||||
|
||||
// s := TestState(t)
|
||||
// defer s.Close()
|
||||
// projRef := testProjectProto(t, s)
|
||||
// projRef := TestProjectProto(t, s)
|
||||
// testRunnerProto(t, s, &vagrant_server.Runner{Id: "R_A"})
|
||||
|
||||
// // Create a build
|
||||
// require.NoError(s.JobCreate(testJobProto(t, &vagrant_server.Job{
|
||||
// require.NoError(s.JobCreate(TestJobProto(t, &vagrant_server.Job{
|
||||
// Id: "A",
|
||||
// Scope: &vagrant_server.Job_Project{
|
||||
// Project: projRef,
|
||||
|
||||
@ -8,14 +8,12 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
serverptypes "github.com/hashicorp/vagrant/internal/server/ptypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestProject_Create(t *testing.T) {
|
||||
t.Run("Requires name, path, and basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Project{})
|
||||
require.Error(result.Error)
|
||||
@ -25,12 +23,12 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -38,12 +36,12 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Name: "default",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -51,7 +49,7 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Project{
|
||||
@ -64,12 +62,12 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Sets resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(&project)
|
||||
require.NoError(result.Error)
|
||||
@ -77,14 +75,14 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Retains resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE_ID"
|
||||
project := Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
ResourceId: rid,
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(&project)
|
||||
require.NoError(result.Error)
|
||||
@ -92,9 +90,9 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate name in same basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := testBasis(t, db)
|
||||
basis := TestBasis(t, db)
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Name: "default",
|
||||
@ -115,13 +113,13 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Allows duplicate name in different basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
@ -129,16 +127,16 @@ func TestProject_Create(t *testing.T) {
|
||||
&Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null/other",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate path in same basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
basis := testBasis(t, db)
|
||||
basis := TestBasis(t, db)
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Name: "default",
|
||||
@ -159,13 +157,13 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Allows duplicate path in different basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
@ -173,14 +171,14 @@ func TestProject_Create(t *testing.T) {
|
||||
&Project{
|
||||
Name: "other",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate resource IDs", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE ID"
|
||||
result := db.Save(
|
||||
@ -188,7 +186,7 @@ func TestProject_Create(t *testing.T) {
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
ResourceId: rid,
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
@ -197,7 +195,7 @@ func TestProject_Create(t *testing.T) {
|
||||
Name: "other",
|
||||
Path: "/dev/null/other",
|
||||
ResourceId: rid,
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -205,13 +203,13 @@ func TestProject_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Creates Vagrantfile when set", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vagrantfile := Vagrantfile{}
|
||||
project := Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
Vagrantfile: &vagrantfile,
|
||||
}
|
||||
result := db.Save(&project)
|
||||
@ -223,12 +221,12 @@ func TestProject_Create(t *testing.T) {
|
||||
|
||||
func TestProject_Update(t *testing.T) {
|
||||
t.Run("Requires name and path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := &Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(project)
|
||||
require.NoError(result.Error)
|
||||
@ -242,12 +240,12 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := &Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(project)
|
||||
require.NoError(result.Error)
|
||||
@ -258,12 +256,12 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires path", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := &Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(project)
|
||||
require.NoError(result.Error)
|
||||
@ -274,12 +272,12 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires basis", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := &Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(project)
|
||||
require.NoError(result.Error)
|
||||
@ -290,12 +288,12 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not update resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(&project)
|
||||
require.NoError(result.Error)
|
||||
@ -313,13 +311,13 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Adds Vagrantfile", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
project := Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(&project)
|
||||
require.NoError(result.Error)
|
||||
@ -331,7 +329,7 @@ func TestProject_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Updates existing Vagrantfile content", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
// Create inital basis
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
@ -340,7 +338,7 @@ func TestProject_Update(t *testing.T) {
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Vagrantfile: v,
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
}
|
||||
result := db.Save(&project)
|
||||
require.NoError(result.Error)
|
||||
@ -372,9 +370,9 @@ func TestProject_Update(t *testing.T) {
|
||||
|
||||
func TestProject_Delete(t *testing.T) {
|
||||
t.Run("Deletes project", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
seedProject := testProject(t, db)
|
||||
seedProject := TestProject(t, db)
|
||||
|
||||
var project Project
|
||||
result := db.First(&project,
|
||||
@ -394,13 +392,13 @@ func TestProject_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deletes Vagrantfile", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
vpath := "/dev/null/Vagrantfile"
|
||||
result := db.Save(&Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
Vagrantfile: &Vagrantfile{Path: &vpath},
|
||||
})
|
||||
require.NoError(result.Error)
|
||||
@ -419,12 +417,12 @@ func TestProject_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deletes targets", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Project{
|
||||
Name: "default",
|
||||
Path: "/dev/null",
|
||||
Basis: testBasis(t, db),
|
||||
Basis: TestBasis(t, db),
|
||||
Targets: []*Target{
|
||||
{
|
||||
Name: "default",
|
||||
@ -477,13 +475,9 @@ func TestProject_State(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
basisRef := testBasisProto(t, s)
|
||||
|
||||
// Set
|
||||
result, err := s.ProjectPut(serverptypes.TestProject(t, &vagrant_server.Project{
|
||||
Basis: basisRef,
|
||||
Path: "idontexist",
|
||||
}))
|
||||
result, err := s.ProjectPut(TestProject(t, s.db).ToProto())
|
||||
require.NoError(err)
|
||||
|
||||
// Get exact
|
||||
@ -510,13 +504,9 @@ func TestProject_State(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
basisRef := testBasisProto(t, s)
|
||||
|
||||
// Set
|
||||
result, err := s.ProjectPut(serverptypes.TestProject(t, &vagrant_server.Project{
|
||||
Basis: basisRef,
|
||||
Path: "idontexist",
|
||||
}))
|
||||
result, err := s.ProjectPut(TestProject(t, s.db).ToProto())
|
||||
require.NoError(err)
|
||||
|
||||
// Read
|
||||
@ -530,7 +520,6 @@ func TestProject_State(t *testing.T) {
|
||||
{
|
||||
err := s.ProjectDelete(&vagrant_plugin_sdk.Ref_Project{
|
||||
ResourceId: result.ResourceId,
|
||||
Basis: basisRef,
|
||||
})
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
|
||||
func TestTarget_Create(t *testing.T) {
|
||||
t.Run("Requires name and project", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Target{})
|
||||
require.Error(result.Error)
|
||||
@ -26,11 +26,11 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -38,7 +38,7 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Requires project", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Target{
|
||||
@ -50,11 +50,11 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Sets resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
target := Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
}
|
||||
result := db.Save(&target)
|
||||
require.NoError(result.Error)
|
||||
@ -62,13 +62,13 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Retains resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE_ID"
|
||||
target := Target{
|
||||
Name: "default",
|
||||
ResourceId: rid,
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
}
|
||||
result := db.Save(&target)
|
||||
require.NoError(result.Error)
|
||||
@ -77,9 +77,9 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate name in same project", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := testProject(t, db)
|
||||
project := TestProject(t, db)
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
@ -98,33 +98,33 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Allows duplicate name in different projects", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
result = db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate resource IDs", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
rid := "RESOURCE ID"
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
ResourceId: rid,
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
@ -132,7 +132,7 @@ func TestTarget_Create(t *testing.T) {
|
||||
&Target{
|
||||
Name: "other",
|
||||
ResourceId: rid,
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -140,14 +140,14 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not allow duplicate UUIDs", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
uuid := "UUID VALUE"
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
Uuid: &uuid,
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.NoError(result.Error)
|
||||
@ -155,7 +155,7 @@ func TestTarget_Create(t *testing.T) {
|
||||
&Target{
|
||||
Name: "other",
|
||||
Uuid: &uuid,
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
},
|
||||
)
|
||||
require.Error(result.Error)
|
||||
@ -163,7 +163,7 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Stores a record when set", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
record := &vagrant_server.Target_Machine{
|
||||
Id: "MACHINE_ID",
|
||||
@ -171,7 +171,7 @@ func TestTarget_Create(t *testing.T) {
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
Record: &ProtoValue{Message: record},
|
||||
},
|
||||
)
|
||||
@ -183,9 +183,9 @@ func TestTarget_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Properly creates child targets", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := testProject(t, db)
|
||||
project := TestProject(t, db)
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "parent",
|
||||
@ -217,9 +217,9 @@ func TestTarget_Create(t *testing.T) {
|
||||
|
||||
func TestTarget_Update(t *testing.T) {
|
||||
t.Run("Requires name", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
target := &Target{Name: "default", Project: testProject(t, db)}
|
||||
target := &Target{Name: "default", Project: TestProject(t, db)}
|
||||
result := db.Save(target)
|
||||
require.NoError(result.Error)
|
||||
|
||||
@ -230,9 +230,9 @@ func TestTarget_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Does not update resource ID", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
target := Target{Name: "default", Project: testProject(t, db)}
|
||||
target := Target{Name: "default", Project: TestProject(t, db)}
|
||||
result := db.Save(&target)
|
||||
require.NoError(result.Error)
|
||||
require.NotEmpty(target.ResourceId)
|
||||
@ -248,11 +248,11 @@ func TestTarget_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Updates the state", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
target := Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
State: vagrant_server.Operation_NOT_CREATED,
|
||||
}
|
||||
result := db.Save(&target)
|
||||
@ -268,9 +268,9 @@ func TestTarget_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Adds subtarget", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := testProject(t, db)
|
||||
project := TestProject(t, db)
|
||||
target := Target{
|
||||
Name: "parent",
|
||||
Project: project,
|
||||
@ -298,11 +298,11 @@ func TestTarget_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("It fails to add subtarget with different project", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
target := Target{
|
||||
Name: "parent",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
}
|
||||
result := db.Save(&target)
|
||||
require.NoError(result.Error)
|
||||
@ -310,7 +310,7 @@ func TestTarget_Update(t *testing.T) {
|
||||
require.NoError(result.Error)
|
||||
target.Subtargets = append(target.Subtargets, &Target{
|
||||
Name: "subtarget",
|
||||
Project: testProject(t, db),
|
||||
Project: TestProject(t, db),
|
||||
})
|
||||
result = db.Save(&target)
|
||||
require.Error(result.Error)
|
||||
@ -319,9 +319,9 @@ func TestTarget_Update(t *testing.T) {
|
||||
|
||||
func TestTarget_Delete(t *testing.T) {
|
||||
t.Run("Deletes target", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
result := db.Save(&Target{Name: "default", Project: testProject(t, db)})
|
||||
result := db.Save(&Target{Name: "default", Project: TestProject(t, db)})
|
||||
require.NoError(result.Error)
|
||||
|
||||
var target Target
|
||||
@ -337,9 +337,9 @@ func TestTarget_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deletes subtargets", func(t *testing.T) {
|
||||
require, db := requireAndDB(t)
|
||||
require, db := RequireAndDB(t)
|
||||
|
||||
project := testProject(t, db)
|
||||
project := TestProject(t, db)
|
||||
result := db.Save(
|
||||
&Target{
|
||||
Name: "parent",
|
||||
@ -393,7 +393,7 @@ func TestTarget_State(t *testing.T) {
|
||||
|
||||
resp, err := s.TargetPut(&vagrant_server.Target{
|
||||
Name: "default",
|
||||
Project: testProject(t, s.db).ToProtoRef(),
|
||||
Project: TestProject(t, s.db).ToProtoRef(),
|
||||
State: vagrant_server.Operation_NOT_CREATED,
|
||||
})
|
||||
require.NoError(err)
|
||||
@ -421,7 +421,7 @@ func TestTarget_State(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projectRef := testProjectProto(t, s)
|
||||
projectRef := TestProjectProto(t, s)
|
||||
|
||||
// Set
|
||||
result, err := s.TargetPut(&vagrant_server.Target{
|
||||
@ -535,7 +535,7 @@ func TestTarget_State(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projectRef := testProjectProto(t, s)
|
||||
projectRef := TestProjectProto(t, s)
|
||||
|
||||
// Set
|
||||
result, err := s.TargetPut(&vagrant_server.Target{
|
||||
@ -582,7 +582,7 @@ func TestTarget_State(t *testing.T) {
|
||||
|
||||
s := TestState(t)
|
||||
defer s.Close()
|
||||
projectRef := testProjectProto(t, s)
|
||||
projectRef := TestProjectProto(t, s)
|
||||
|
||||
// Set
|
||||
result, err := s.TargetPut(&vagrant_server.Target{
|
||||
|
||||
@ -105,7 +105,7 @@ func TestDB(t testing.T) *gorm.DB {
|
||||
return db
|
||||
}
|
||||
|
||||
func requireAndDB(t testing.T) (*require.Assertions, *gorm.DB) {
|
||||
func RequireAndDB(t testing.T) (*require.Assertions, *gorm.DB) {
|
||||
db := TestDB(t)
|
||||
require := require.New(t)
|
||||
if err := db.AutoMigrate(models...); err != nil {
|
||||
@ -114,10 +114,10 @@ func requireAndDB(t testing.T) (*require.Assertions, *gorm.DB) {
|
||||
return require, db
|
||||
}
|
||||
|
||||
func testBasis(t testing.T, db *gorm.DB) *Basis {
|
||||
func TestBasis(t testing.T, db *gorm.DB) *Basis {
|
||||
t.Helper()
|
||||
|
||||
td := testTempDir(t)
|
||||
td := TestTempDir(t)
|
||||
b := &Basis{
|
||||
Name: filepath.Base(td),
|
||||
Path: td,
|
||||
@ -129,16 +129,16 @@ func testBasis(t testing.T, db *gorm.DB) *Basis {
|
||||
}
|
||||
|
||||
// TestBasis creates the basis in the DB.
|
||||
func testBasisProto(t testing.T, s *State) *vagrant_plugin_sdk.Ref_Basis {
|
||||
func TestBasisProto(t testing.T, s *State) *vagrant_plugin_sdk.Ref_Basis {
|
||||
t.Helper()
|
||||
|
||||
return testBasis(t, s.db).ToProtoRef()
|
||||
return TestBasis(t, s.db).ToProtoRef()
|
||||
}
|
||||
|
||||
func testProject(t testing.T, db *gorm.DB) *Project {
|
||||
b := testBasis(t, db)
|
||||
func TestProject(t testing.T, db *gorm.DB) *Project {
|
||||
b := TestBasis(t, db)
|
||||
|
||||
td := testTempDir(t)
|
||||
td := TestTempDir(t)
|
||||
p := &Project{
|
||||
Name: filepath.Base(td),
|
||||
Path: td,
|
||||
@ -150,10 +150,10 @@ func testProject(t testing.T, db *gorm.DB) *Project {
|
||||
return p
|
||||
}
|
||||
|
||||
func testProjectProto(t testing.T, s *State) *vagrant_plugin_sdk.Ref_Project {
|
||||
func TestProjectProto(t testing.T, s *State) *vagrant_plugin_sdk.Ref_Project {
|
||||
t.Helper()
|
||||
|
||||
return testProject(t, s.db).ToProtoRef()
|
||||
return TestProject(t, s.db).ToProtoRef()
|
||||
}
|
||||
|
||||
func testRunnerProto(t testing.T, s *State, src *vagrant_server.Runner) *vagrant_server.Runner {
|
||||
@ -175,7 +175,7 @@ func testRunnerProto(t testing.T, s *State, src *vagrant_server.Runner) *vagrant
|
||||
return runner.ToProto()
|
||||
}
|
||||
|
||||
func testJobProto(t testing.T, src *vagrant_server.Job) *vagrant_server.Job {
|
||||
func TestJobProto(t testing.T, src *vagrant_server.Job) *vagrant_server.Job {
|
||||
t.Helper()
|
||||
|
||||
require.NoError(t, mergo.Merge(src,
|
||||
@ -199,7 +199,7 @@ func testJobProto(t testing.T, src *vagrant_server.Job) *vagrant_server.Job {
|
||||
return src
|
||||
}
|
||||
|
||||
func testTempDir(t testing.T) string {
|
||||
func TestTempDir(t testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
dir, err := ioutil.TempDir("", "vagrant-test")
|
||||
|
||||
@ -4,13 +4,16 @@ import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server"
|
||||
pb "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
"github.com/hashicorp/vagrant/internal/server/singleprocess/state"
|
||||
@ -138,19 +141,47 @@ func TestRunner(t testing.T, client pb.VagrantClient, r *pb.Runner) (string, fun
|
||||
}
|
||||
|
||||
// TestBasis creates the basis in the DB.
|
||||
func TestBasis(t testing.T, client pb.VagrantClient, ref *pb.Basis) {
|
||||
func TestBasis(t testing.T, client pb.VagrantClient, ref *pb.Basis) *pb.Basis {
|
||||
if ref == nil {
|
||||
ref = &pb.Basis{}
|
||||
}
|
||||
|
||||
td := testTempDir(t)
|
||||
defaultBasis := &pb.Basis{
|
||||
Name: "test",
|
||||
Name: filepath.Base(td),
|
||||
Path: td,
|
||||
}
|
||||
|
||||
require.NoError(t, mergo.Merge(ref, defaultBasis))
|
||||
|
||||
_, err := client.UpsertBasis(context.Background(), &pb.UpsertBasisRequest{
|
||||
resp, err := client.UpsertBasis(context.Background(), &pb.UpsertBasisRequest{
|
||||
Basis: ref,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
return resp.Basis
|
||||
}
|
||||
|
||||
func TestJob(t testing.T, client pb.VagrantClient, ref *pb.Job) *pb.Job {
|
||||
var job pb.Job
|
||||
|
||||
if ref == nil {
|
||||
ref = &pb.Job{}
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(ref, &job)
|
||||
require.NoError(t, err)
|
||||
|
||||
if job.Scope == nil {
|
||||
basis := TestBasis(t, client, nil)
|
||||
job.Scope = &pb.Job_Basis{
|
||||
Basis: &vagrant_plugin_sdk.Ref_Basis{
|
||||
ResourceId: basis.ResourceId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return state.TestJobProto(t, &job)
|
||||
}
|
||||
|
||||
func testDB(t testing.T) *gorm.DB {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user