summaryrefslogtreecommitdiff
path: root/src/pkg/io/ioutil/tempfile_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-06-03 16:29:34 -0700
committerRuss Cox <rsc@golang.org>2010-06-03 16:29:34 -0700
commit6d99efafb928558e0b5a111df8c8b2d245444dca (patch)
treedaeb88f9c3286b4a759a4fa59013addceb97629e /src/pkg/io/ioutil/tempfile_test.go
parent005a11f5473c07a7b669bfc30f56e05ca1af06a3 (diff)
downloadgolang-6d99efafb928558e0b5a111df8c8b2d245444dca.tar.gz
io/ioutil: add TempFile
R=r CC=golang-dev http://codereview.appspot.com/1472042
Diffstat (limited to 'src/pkg/io/ioutil/tempfile_test.go')
-rw-r--r--src/pkg/io/ioutil/tempfile_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/pkg/io/ioutil/tempfile_test.go b/src/pkg/io/ioutil/tempfile_test.go
new file mode 100644
index 000000000..fbe45dc6d
--- /dev/null
+++ b/src/pkg/io/ioutil/tempfile_test.go
@@ -0,0 +1,29 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ioutil_test
+
+import (
+ . "io/ioutil"
+ "os"
+ "testing"
+)
+
+func TestTempFile(t *testing.T) {
+ f, err := TempFile("/_not_exists_", "foo")
+ if f != nil || err == nil {
+ t.Errorf("TempFile(`/_not_exists_`, `foo`) = %v, %v", f, err)
+ }
+
+ f, err = TempFile("/tmp", "ioutil_test")
+ if f == nil || err != nil {
+ t.Errorf("TempFile(`/tmp`, `ioutil_test`) = %v, %v", f, err)
+ }
+ re := testing.MustCompile("^/tmp/ioutil_test[0-9]+$")
+ if !re.MatchString(f.Name()) {
+ t.Fatalf("TempFile(`/tmp`, `ioutil_test`) created bad name %s", f.Name())
+ }
+ os.Remove(f.Name())
+ f.Close()
+}