cleanup workspace interface

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-06-16 14:58:05 +02:00
committed by Solomon Hykes
parent 7f456b9131
commit b393ecc034
3 changed files with 15 additions and 5 deletions

View File

@@ -229,7 +229,12 @@ func (w *Workspace) Save(ctx context.Context, st *State) error {
return nil
}
func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*State, error) {
type CreateOpts struct {
Module string
Package string
}
func (w *Workspace) Create(ctx context.Context, name string, opts CreateOpts) (*State, error) {
envPath, err := filepath.Abs(w.envPath(name))
if err != nil {
return nil, err
@@ -247,6 +252,7 @@ func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*Stat
// Backward compat: if no plan module has been provided,
// use `.dagger/env/<name>/plan`
module := opts.Module
if module == "" {
planPath := path.Join(envPath, planDir)
if err := os.Mkdir(planPath, 0755); err != nil {
@@ -265,7 +271,7 @@ func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*Stat
Workspace: w.Path,
Plan: Plan{
Module: module,
Package: pkg,
Package: opts.Package,
},
Name: name,
}

View File

@@ -27,7 +27,7 @@ func TestWorkspace(t *testing.T) {
require.Equal(t, root, workspace.Path)
// Create
st, err := workspace.Create(ctx, "test", "", "")
st, err := workspace.Create(ctx, "test", CreateOpts{})
require.NoError(t, err)
require.Equal(t, "test", st.Name)
@@ -73,7 +73,7 @@ func TestEncryption(t *testing.T) {
workspace, err := Init(ctx, root)
require.NoError(t, err)
_, err = workspace.Create(ctx, "test", "", "")
_, err = workspace.Create(ctx, "test", CreateOpts{})
require.NoError(t, err)
// Set a plaintext input, make sure it is not encrypted