github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/tmpfile_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "os" 8 "strings" 9 "testing" 10 ) 11 12 func TestTempFile(t *testing.T) { 13 name, file, err := OpenTempFile("test", "", 0700) 14 if err != nil { 15 t.Errorf("%s", err) 16 } 17 defer file.Close() 18 if file == nil { 19 t.Fatalf("No file") 20 } 21 defer os.Remove(name) 22 if !strings.HasPrefix(name, "test.") { 23 t.Errorf("Bad temp file name: %s", name) 24 } 25 if len(name) < 37 { 26 t.Errorf("Bad temp file name length: %s", name) 27 } 28 }