github.com/blend/go-sdk@v1.20220411.3/sh/to_file_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package sh
     9  
    10  import (
    11  	"os"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  	"github.com/blend/go-sdk/uuid"
    16  )
    17  
    18  func TestToFileCreate(t *testing.T) {
    19  	assert := assert.New(t)
    20  
    21  	// create a new file
    22  	filename := uuid.V4().String() + ".temp"
    23  	defer func() {
    24  		os.Remove(filename)
    25  	}()
    26  	file, err := ToFile(filename)
    27  	assert.Nil(err)
    28  	_, err = file.Stat()
    29  	assert.Nil(err)
    30  	assert.Nil(file.Close())
    31  }
    32  
    33  func TestToFileOpen(t *testing.T) {
    34  	assert := assert.New(t)
    35  
    36  	// create a new file
    37  	filename := uuid.V4().String() + ".temp"
    38  	assert.Nil(Touch(filename))
    39  	defer func() {
    40  		os.Remove(filename)
    41  	}()
    42  
    43  	file, err := ToFile(filename)
    44  	assert.Nil(err)
    45  	_, err = file.Stat()
    46  	assert.Nil(err)
    47  }