github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/perf/json/utils_test.go (about)

     1  package json
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestLoadAndDump(t *testing.T) {
    12  	tmpFile, err := os.CreateTemp("", "")
    13  	require.Nil(t, err)
    14  	tmpFile.Close()
    15  	defer os.Remove(tmpFile.Name())
    16  
    17  	data := []int{1, 2, 3}
    18  
    19  	err = Dump(tmpFile.Name(), data, "", "  ")
    20  	require.Nil(t, err)
    21  
    22  	var got []int64
    23  	err = Load(tmpFile.Name(), &got)
    24  	require.Nil(t, err)
    25  	assert.Equal(t, []int64{1, 2, 3}, got)
    26  }