github.com/dnephin/dobi@v0.15.0/tasks/mount/mount_test.go (about)

     1  package mount
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/dnephin/dobi/config"
     7  	"github.com/dnephin/dobi/tasks/context"
     8  	"github.com/dnephin/dobi/tasks/task"
     9  	"gotest.tools/v3/assert"
    10  	"gotest.tools/v3/fs"
    11  )
    12  
    13  func defaultExecContext(path string) *context.ExecuteContext {
    14  	return context.NewExecuteContext(
    15  		&config.Config{WorkingDir: path},
    16  		nil,
    17  		nil,
    18  		context.Settings{})
    19  }
    20  
    21  func TestTaskRun(t *testing.T) {
    22  	dir := fs.NewDir(t, "test-mount-task")
    23  	defer dir.Remove()
    24  
    25  	ctx := defaultExecContext(dir.Path())
    26  	task := &Task{
    27  		name: task.NewName("resource", "action"),
    28  		config: &config.MountConfig{
    29  			Bind: "a/b/c",
    30  			Path: "/target",
    31  		},
    32  		run: runCreate,
    33  	}
    34  
    35  	modified, err := task.Run(ctx, false)
    36  	assert.NilError(t, err)
    37  	assert.Assert(t, modified)
    38  
    39  	action := &createAction{task: task}
    40  	assert.Assert(t, action.exists(ctx))
    41  
    42  	// Next run is a no-op
    43  	modified, err = task.Run(ctx, false)
    44  	assert.NilError(t, err)
    45  	assert.Assert(t, !modified)
    46  }
    47  
    48  func TestAsBind(t *testing.T) {
    49  	workDir := "/working"
    50  	mountConf := &config.MountConfig{
    51  		Path: "/target",
    52  		Bind: "./a/b/c",
    53  	}
    54  	expected := "/working/a/b/c:/target:rw"
    55  	assert.Equal(t, AsBind(mountConf, workDir), expected)
    56  }