tpmfile_test.go 474 B

123456789101112131415161718192021222324252627
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package utils
  3. import (
  4. "fmt"
  5. "runtime"
  6. "strconv"
  7. "testing"
  8. )
  9. var _ = fmt.Print
  10. func TestCreateAnonymousTempfile(t *testing.T) {
  11. f, err := CreateAnonymousTemp("")
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. fd := int64(f.Fd())
  16. f.Close()
  17. if runtime.GOOS == "linux" {
  18. if f.Name() != "/proc/self/fd/"+strconv.FormatInt(fd, 10) {
  19. t.Fatalf("Anonymous tempfile was not created atomically")
  20. }
  21. }
  22. }