diff --git a/pkg/config/resources/exec/resource.go b/pkg/config/resources/exec/resource.go index 57e492a7..380889a4 100644 --- a/pkg/config/resources/exec/resource.go +++ b/pkg/config/resources/exec/resource.go @@ -1,6 +1,7 @@ package exec import ( + "fmt" "strings" "github.com/jumppad-labs/hclconfig/types" @@ -46,6 +47,10 @@ func (e *Exec) Process() error { // make sure line endings are linux e.Script = strings.Replace(e.Script, "\r\n", "\n", -1) + } else { + if len(e.Networks) > 0 || len(e.Volumes) > 0 { + return fmt.Errorf("unable to create local exec with networks or volumes") + } } // do we have an existing resource in the state? diff --git a/pkg/config/resources/exec/resource_test.go b/pkg/config/resources/exec/resource_test.go index 25da9c9c..cf56a22d 100644 --- a/pkg/config/resources/exec/resource_test.go +++ b/pkg/config/resources/exec/resource_test.go @@ -1,13 +1,20 @@ package exec import ( + "os" "testing" "github.com/jumppad-labs/hclconfig/types" + "github.com/jumppad-labs/jumppad/pkg/config" + ctypes "github.com/jumppad-labs/jumppad/pkg/config/resources/container" "github.com/jumppad-labs/jumppad/testutils" "github.com/stretchr/testify/require" ) +func init() { + config.RegisterResource(TypeExec, &Exec{}, &Provider{}) +} + func TestExecSetsOutputsFromState(t *testing.T) { testutils.SetupState(t, ` { @@ -33,3 +40,54 @@ func TestExecSetsOutputsFromState(t *testing.T) { require.Equal(t, 42, c.PID) } + +func TestExecProcessSetsAbsolute(t *testing.T) { + wd, err := os.Getwd() + require.NoError(t, err) + + c := &Exec{ + ResourceMetadata: types.ResourceMetadata{File: "./"}, + Image: &ctypes.Image{ + Name: "test", + }, + Volumes: []ctypes.Volume{ + { + Source: "./", + Destination: "./", + }, + }, + } + + c.Process() + + require.Equal(t, wd, c.Volumes[0].Source) +} + +func TestExecLocalWithVolumesReturnsError(t *testing.T) { + c := &Exec{ + ResourceMetadata: types.ResourceMetadata{File: "./"}, + Volumes: []ctypes.Volume{ + { + Source: "./", + Destination: "./", + }, + }, + } + + err := c.Process() + require.Error(t, err) +} + +func TestExecLocalWithNetworksReturnsError(t *testing.T) { + c := &Exec{ + ResourceMetadata: types.ResourceMetadata{File: "./"}, + Networks: []ctypes.NetworkAttachment{ + { + Name: "test", + }, + }, + } + + err := c.Process() + require.Error(t, err) +}