Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: vpython/filesystem/testfs/tempdir.go

Issue 2703793003: vpython: Add filesystem operation / test packages. (Closed)
Patch Set: test now path Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « vpython/filesystem/testfs/build.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package testfs
6
7 import (
8 "io/ioutil"
9 "testing"
10
11 "github.com/luci/luci-go/vpython/filesystem"
12 )
13
14 // WithTempDir creates a temporary directory and passes it to fn. After fn
15 // exits, the directory is cleaned up.
16 func WithTempDir(t *testing.T, prefix string, fn func(string) error) error {
17 tdir, err := ioutil.TempDir("", prefix)
18 if err != nil {
19 return err
20 }
21 defer func() {
22 if rmErr := filesystem.RemoveAll(tdir); rmErr != nil {
23 t.Errorf("failed to remove temporary directory [%s]: %s" , tdir, rmErr)
24 }
25 }()
26 return fn(tdir)
27 }
28
29 // MustWithTempDir calls WithTempDir and panics if any failures occur.
30 func MustWithTempDir(t *testing.T, prefix string, fn func(string)) func() {
31 return func() {
32 err := WithTempDir(t, prefix, func(tdir string) error {
33 fn(tdir)
34 return nil
35 })
36 if err != nil {
37 panic(err)
38 }
39 }
40 }
OLDNEW
« no previous file with comments | « vpython/filesystem/testfs/build.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698