github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/engine/docker/helper_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"io/ioutil"
     7  	"os"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  
    13  	coreutils "github.com/projecteru2/core/utils"
    14  )
    15  
    16  func TestCreateTarStream(t *testing.T) {
    17  	buff := bytes.NewBufferString("test")
    18  	rc := ioutil.NopCloser(buff)
    19  	fname, err := coreutils.TempFile(rc)
    20  	assert.NoError(t, err)
    21  	_, err = CreateTarStream(fname)
    22  	assert.NoError(t, err)
    23  }
    24  
    25  func TestWithDumpFiles(t *testing.T) {
    26  	data := map[string][]byte{
    27  		"/tmp/test-1": []byte("1"),
    28  		"/tmp/test-2": []byte("2"),
    29  	}
    30  	fp := []string{}
    31  	for target, content := range data {
    32  		withTarfileDump(context.Background(), target, content, 0, 0, int64(0), func(target, tarfile string) error {
    33  			assert.True(t, strings.HasPrefix(target, "/tmp/test"))
    34  			fp = append(fp, tarfile)
    35  			_, err := os.Stat(tarfile)
    36  			assert.Nil(t, err)
    37  			return nil
    38  		})
    39  	}
    40  	for _, path := range fp {
    41  		_, err := os.Stat(path)
    42  		assert.True(t, os.IsNotExist(err))
    43  	}
    44  }