github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/elvish/util/claim_test.go (about) 1 package util 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 var claimFileTests = []struct { 9 pattern string 10 wantFileName string 11 }{ 12 {"a*.log", "a9.log"}, 13 {"*.txt", "1.txt"}, 14 } 15 16 func TestClaimFile(t *testing.T) { 17 InTempDir(func(tmpdir string) { 18 touch("a0.log") 19 touch("a1.log") 20 touch("a8.log") 21 22 for _, test := range claimFileTests { 23 f, err := ClaimFile(".", test.pattern) 24 if err != nil { 25 t.Errorf("ClaimFile errors: %v", err) 26 } 27 if f.Name() != test.wantFileName { 28 t.Errorf("ClaimFile claims %s, want %s", f.Name(), test.wantFileName) 29 } 30 } 31 }) 32 } 33 34 func touch(fname string) { 35 f, err := os.Create(fname) 36 if err != nil { 37 panic(err) 38 } 39 f.Close() 40 }