github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/mmap/mmap_test.go (about)

     1  package mmap
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func TestReadFile(t *testing.T) {
     9  	f, err := os.CreateTemp(t.TempDir(), "mmap_ReadFile_test")
    10  	if err != nil {
    11  		t.Fatal(err)
    12  	}
    13  	name := f.Name()
    14  	defer os.Remove(name)
    15  
    16  	_, err = f.WriteString(name)
    17  	f.Close()
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  
    22  	t.Logf("Created temporary test file: %s", name)
    23  
    24  	data, err := ReadFile[string](name)
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	if data != name {
    29  		t.Errorf("Expected file content %s, got %s", name, data)
    30  	}
    31  
    32  	if err = Unmap(data); err != nil {
    33  		t.Fatal(err)
    34  	}
    35  }