Make no-op test work
This commit is contained in:
parent
8ca1a29e93
commit
70b71dc39e
@ -1,74 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/ceb"
|
||||
"github.com/hashicorp/vagrant/internal/pkg/signalcontext"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(realMain())
|
||||
}
|
||||
|
||||
func realMain() int {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
usage()
|
||||
return 1
|
||||
}
|
||||
|
||||
// TODO(mitchellh): proper log setup
|
||||
log := hclog.L()
|
||||
hclog.L().SetLevel(hclog.Trace)
|
||||
|
||||
// Create a context that is cancelled on interrupt
|
||||
ctx, closer := signalcontext.WithInterrupt(context.Background(), log)
|
||||
defer closer()
|
||||
|
||||
// Run our core logic
|
||||
err := ceb.Run(ctx,
|
||||
ceb.WithEnvDefaults(),
|
||||
ceb.WithExec(args))
|
||||
if err != nil {
|
||||
fmt.Fprintf(flag.CommandLine.Output(),
|
||||
"Error initializing Vagrant entrypoint: %s\n", formatError(err))
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func formatError(err error) string {
|
||||
if s, ok := status.FromError(err); ok {
|
||||
return s.Message()
|
||||
}
|
||||
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(),
|
||||
strings.TrimLeftFunc(usageText, unicode.IsSpace),
|
||||
os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
const usageText = `
|
||||
Usage: %[1]s [cmd] [args...]
|
||||
|
||||
This the custom entrypoint to support Vagrant. It will re-execute any
|
||||
command given after configuring the environment for usage with Vagrant.
|
||||
|
||||
`
|
||||
2
go.sum
2
go.sum
@ -257,6 +257,7 @@ github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.
|
||||
github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
|
||||
github.com/containerd/containerd v1.3.3 h1:LoIzb5y9x5l8VKAlyrbusNPXqBY0+kviRloxFUMFwKc=
|
||||
github.com/containerd/containerd v1.3.3/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
|
||||
github.com/containerd/containerd v1.4.3 h1:ijQT13JedHSHrQGWFcGEwzcNKrAGIiZ+jSD5QQG07SY=
|
||||
github.com/containerd/containerd v1.4.3/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
|
||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||
github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41 h1:kIFnQBO7rQ0XkMe6xEwbybYHBEaWmh/f++laI6Emt7M=
|
||||
@ -541,6 +542,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
|
||||
github.com/golang-migrate/migrate/v4 v4.10.0 h1:76R6UL3BGnDTpYeittMtfpaNvGBH5zMZatO/fCzIjWo=
|
||||
|
||||
@ -6,8 +6,6 @@ import (
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/server/singleprocess"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -17,15 +15,10 @@ func init() {
|
||||
func TestProjectNoop(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
require := require.New(t)
|
||||
client := singleprocess.TestServer(t)
|
||||
|
||||
// Build our client
|
||||
c := TestProject(t, WithClient(client), WithLocal())
|
||||
app := c.App(TestApp(t, c))
|
||||
|
||||
// TODO(mitchellh): once we have an API to list jobs, verify we have
|
||||
// no jobs, and then verify we execute a job after.
|
||||
tp := TestBasis(t)
|
||||
|
||||
// Noop
|
||||
require.NoError(app.Noop(ctx))
|
||||
require.NoError(tp.Noop(ctx))
|
||||
}
|
||||
|
||||
@ -1,69 +1,59 @@
|
||||
package client
|
||||
|
||||
// import (
|
||||
// "context"
|
||||
// "io/ioutil"
|
||||
// "os"
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
// "github.com/mitchellh/go-testing-interface"
|
||||
// "github.com/stretchr/testify/require"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
// configpkg "github.com/hashicorp/vagrant/internal/config"
|
||||
// pb "github.com/hashicorp/vagrant/internal/server/gen"
|
||||
// "github.com/hashicorp/vagrant/internal/server/singleprocess"
|
||||
// )
|
||||
"github.com/hashicorp/vagrant/internal/server/singleprocess"
|
||||
)
|
||||
|
||||
// // TestProject returns an initialized client pointing to an in-memory test
|
||||
// // server. This will close automatically on test completion.
|
||||
// //
|
||||
// // This will also change the working directory to a temporary directory
|
||||
// // so that any side effect file creation doesn't impact the real working
|
||||
// // directory. If you need to use your working directory, query it before
|
||||
// // calling this.
|
||||
// func TestProject(t testing.T, opts ...Option) *Project {
|
||||
// require := require.New(t)
|
||||
// client := singleprocess.TestServer(t)
|
||||
// TestBasis returns an initialized client pointing to an in-memory test
|
||||
// server. This will close automatically on test completion.
|
||||
//
|
||||
// This will also change the working directory to a temporary directory
|
||||
// so that any side effect file creation doesn't impact the real working
|
||||
// directory. If you need to use your working directory, query it before
|
||||
// calling this.
|
||||
func TestBasis(t testing.T, opts ...Option) *Basis {
|
||||
require := require.New(t)
|
||||
client := singleprocess.TestServer(t)
|
||||
|
||||
// ctx := context.Background()
|
||||
ctx := context.Background()
|
||||
|
||||
// basis, err := NewBasis(ctx, WithClient(client), WithLocal())
|
||||
// require.NoError(err)
|
||||
basis, err := New(ctx, WithClient(client), WithLocal())
|
||||
require.NoError(err)
|
||||
|
||||
// // Initialize our client
|
||||
// result, err := New(ctx, append([]Option{
|
||||
// WithBasis(basis),
|
||||
// WithProjectRef(&pb.Ref_Project{Project: "test_p"}),
|
||||
// }, opts...)...)
|
||||
// require.NoError(err)
|
||||
// // Initialize our client
|
||||
// result, err := New(ctx, append([]Option{
|
||||
// WithBasis(basis),
|
||||
// WithProjectRef(&pb.Ref_Project{Project: "test_p"}),
|
||||
// }, opts...)...)
|
||||
// require.NoError(err)
|
||||
|
||||
// // Move into a temporary directory
|
||||
// td := testTempDir(t)
|
||||
// testChdir(t, td)
|
||||
// Move into a temporary directory
|
||||
td := testTempDir(t)
|
||||
testChdir(t, td)
|
||||
|
||||
// // Create a valid vagrant configuration file
|
||||
// configpkg.TestConfigFile(t, configpkg.TestSource(t))
|
||||
// Create a valid vagrant configuration file
|
||||
// configpkg.TestConfigFile(t, configpkg.TestSource(t))
|
||||
|
||||
// return result
|
||||
// }
|
||||
return basis
|
||||
}
|
||||
|
||||
// // TestApp returns an app reference that can be used for testing.
|
||||
// func TestApp(t testing.T, c *Project) string {
|
||||
// // Initialize our app
|
||||
// singleprocess.TestApp(t, c.Client(), c.App("test_a").Ref())
|
||||
func testChdir(t testing.T, dir string) {
|
||||
pwd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.Chdir(dir))
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(pwd)) })
|
||||
}
|
||||
|
||||
// return "test_a"
|
||||
// }
|
||||
|
||||
// func testChdir(t testing.T, dir string) {
|
||||
// pwd, err := os.Getwd()
|
||||
// require.NoError(t, err)
|
||||
// require.NoError(t, os.Chdir(dir))
|
||||
// t.Cleanup(func() { require.NoError(t, os.Chdir(pwd)) })
|
||||
// }
|
||||
|
||||
// func testTempDir(t testing.T) string {
|
||||
// dir, err := ioutil.TempDir("", "vagrant-test")
|
||||
// require.NoError(t, err)
|
||||
// t.Cleanup(func() { os.RemoveAll(dir) })
|
||||
// return dir
|
||||
// }
|
||||
func testTempDir(t testing.T) string {
|
||||
dir, err := ioutil.TempDir("", "vagrant-test")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(dir) })
|
||||
return dir
|
||||
}
|
||||
|
||||
@ -1,128 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConfigAppPlugins(t *testing.T) {
|
||||
cases := []struct {
|
||||
File string
|
||||
TestAll func(*testing.T, []*Plugin)
|
||||
TestByName map[string]func(*testing.T, *Plugin)
|
||||
}{
|
||||
{
|
||||
"none.hcl",
|
||||
func(t *testing.T, ps []*Plugin) {
|
||||
require.Empty(t, ps)
|
||||
},
|
||||
nil,
|
||||
},
|
||||
|
||||
{
|
||||
"explicit.hcl",
|
||||
func(t *testing.T, ps []*Plugin) {
|
||||
require.Len(t, ps, 2)
|
||||
},
|
||||
map[string]func(*testing.T, *Plugin){
|
||||
"go1": func(t *testing.T, p *Plugin) {
|
||||
require.True(t, p.Type.Mapper)
|
||||
require.False(t, p.Type.Registry)
|
||||
},
|
||||
|
||||
"go2": func(t *testing.T, p *Plugin) {
|
||||
require.False(t, p.Type.Mapper)
|
||||
require.True(t, p.Type.Registry)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"implicit.hcl",
|
||||
func(t *testing.T, ps []*Plugin) {
|
||||
require.Len(t, ps, 2)
|
||||
},
|
||||
map[string]func(*testing.T, *Plugin){
|
||||
"docker": func(t *testing.T, p *Plugin) {
|
||||
require.True(t, p.Type.Builder)
|
||||
require.False(t, p.Type.Platform)
|
||||
require.True(t, p.Type.Mapper)
|
||||
},
|
||||
|
||||
"nomad": func(t *testing.T, p *Plugin) {
|
||||
require.False(t, p.Type.Builder)
|
||||
require.True(t, p.Type.Platform)
|
||||
require.True(t, p.Type.Mapper)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"implicit_registry.hcl",
|
||||
func(t *testing.T, ps []*Plugin) {
|
||||
require.Len(t, ps, 3)
|
||||
},
|
||||
map[string]func(*testing.T, *Plugin){
|
||||
"docker": func(t *testing.T, p *Plugin) {
|
||||
require.True(t, p.Type.Builder)
|
||||
require.False(t, p.Type.Platform)
|
||||
},
|
||||
|
||||
"aws-ecr": func(t *testing.T, p *Plugin) {
|
||||
require.False(t, p.Type.Builder)
|
||||
require.True(t, p.Type.Registry)
|
||||
},
|
||||
|
||||
"nomad": func(t *testing.T, p *Plugin) {
|
||||
require.False(t, p.Type.Builder)
|
||||
require.True(t, p.Type.Platform)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"mix.hcl",
|
||||
func(t *testing.T, ps []*Plugin) {
|
||||
require.Len(t, ps, 2)
|
||||
},
|
||||
map[string]func(*testing.T, *Plugin){
|
||||
"docker": func(t *testing.T, p *Plugin) {
|
||||
require.True(t, p.Type.Builder)
|
||||
require.True(t, p.Type.Platform)
|
||||
},
|
||||
|
||||
"nomad": func(t *testing.T, p *Plugin) {
|
||||
require.False(t, p.Type.Builder)
|
||||
require.True(t, p.Type.Platform)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.File, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
cfg, err := Load(filepath.Join("testdata", "plugins", tt.File), "")
|
||||
require.NoError(err)
|
||||
|
||||
ps := cfg.Plugins()
|
||||
tt.TestAll(t, ps)
|
||||
|
||||
psMap := map[string]*Plugin{}
|
||||
for _, p := range ps {
|
||||
if _, ok := psMap[p.Name]; ok {
|
||||
t.Fatal("duplicate plugin: " + p.Name)
|
||||
}
|
||||
|
||||
psMap[p.Name] = p
|
||||
}
|
||||
|
||||
for n, f := range tt.TestByName {
|
||||
f(t, psMap[n])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -31,16 +31,3 @@ func TestTargetSpecializeBad(t *testing.T) {
|
||||
t.Errorf("Should not specialize to an unsupported type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
// TODO: needs
|
||||
// - to be able to create a Task
|
||||
// tt, _ := TestTarget(t)
|
||||
// ctx := context.Background()
|
||||
// tk := &vagrant_server.Task{}
|
||||
|
||||
// err := tt.Run(ctx, tk)
|
||||
// if err != nil {
|
||||
// t.Errorf("Run returned an error")
|
||||
// }
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ var TestingTypeMap = map[component.Type]interface{}{
|
||||
// factories, configuration, etc.
|
||||
func TestTarget(t testing.T, opts ...BasisOption) (target *Target, err error) {
|
||||
tp := TestProject(t, opts...)
|
||||
// vagrantServerTarget, err :=
|
||||
tp.basis.client.UpsertTarget(
|
||||
context.Background(),
|
||||
&vagrant_server.UpsertTargetRequest{
|
||||
@ -52,11 +51,6 @@ func TestTarget(t testing.T, opts ...BasisOption) (target *Target, err error) {
|
||||
WithTargetRef(&vagrant_plugin_sdk.Ref_Target{Project: tp.Ref().(*vagrant_plugin_sdk.Ref_Project), Name: "test-target"}),
|
||||
}...)
|
||||
|
||||
// return &Target{
|
||||
// target: &vagrant_server.Target{},
|
||||
// logger: hclog.New(&hclog.LoggerOptions{Name: "test"}),
|
||||
// }
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -64,6 +58,15 @@ func TestTarget(t testing.T, opts ...BasisOption) (target *Target, err error) {
|
||||
// can be used for testing. Additional options can be given to provide your own
|
||||
// factories, configuration, etc.
|
||||
func TestProject(t testing.T, opts ...BasisOption) *Project {
|
||||
b := TestBasis(t, opts...)
|
||||
|
||||
p, _ := b.LoadProject([]ProjectOption{
|
||||
WithProjectRef(&vagrant_plugin_sdk.Ref_Project{Basis: b.Ref().(*vagrant_plugin_sdk.Ref_Basis), Name: "test-project"}),
|
||||
}...)
|
||||
return p
|
||||
}
|
||||
|
||||
func TestBasis(t testing.T, opts ...BasisOption) (b *Basis) {
|
||||
td, err := ioutil.TempDir("", "core")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(td) })
|
||||
@ -83,15 +86,8 @@ func TestProject(t testing.T, opts ...BasisOption) *Project {
|
||||
defaultOpts = append(defaultOpts, WithFactory(typ, f))
|
||||
}
|
||||
|
||||
// p, err := NewProject(context.Background(), append(defaultOpts, opts...)...)
|
||||
// require.NoError(t, err)
|
||||
// t.Cleanup(func() { p.Close() })
|
||||
b, err := NewBasis(context.Background(), append(defaultOpts, opts...)...)
|
||||
|
||||
p, err := b.LoadProject([]ProjectOption{
|
||||
WithProjectRef(&vagrant_plugin_sdk.Ref_Project{Basis: b.Ref().(*vagrant_plugin_sdk.Ref_Basis), Name: "test-project"}),
|
||||
}...)
|
||||
return p
|
||||
b, _ = NewBasis(context.Background(), append(defaultOpts, opts...)...)
|
||||
return
|
||||
}
|
||||
|
||||
// TestFactorySingle creates a factory for the given component type and
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user