github.com/kubeshop/testkube@v1.17.23/pkg/tmp/files_test.go (about)

     1  package tmp
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestReaderToTmpfile(t *testing.T) {
    12  	const content = "test content"
    13  	buffer := strings.NewReader(content)
    14  
    15  	// when
    16  	path, err := ReaderToTmpfile(buffer)
    17  
    18  	// then
    19  	assert.NoError(t, err)
    20  	defer os.Remove(path) // clean up
    21  
    22  	contentBytes, err := os.ReadFile(path)
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  
    27  	assert.Equal(t, content, string(contentBytes))
    28  
    29  }