github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Retitle_test.go (about) 1 package fitapp 2 3 import ( 4 "fmt" 5 bugs "github.com/grantbow/fit/issues" 6 "os" 7 "regexp" 8 "testing" 9 ) 10 11 func runretitle(label string, args argumentList, config bugs.Config, expected string, t *testing.T) { 12 stdout, _ := captureOutput(func() { 13 Relabel(args, config) // name might change 14 }, t) 15 re := regexp.MustCompile(expected) 16 matched := re.MatchString(stdout) 17 if !matched { 18 t.Errorf("Unexpected output on STDOUT for fitapp/Retitle_test %s.", label) 19 fmt.Printf("Expected to match: %s\nGot: %s\n", expected, stdout) 20 } 21 } 22 23 func TestRetitle(t *testing.T) { 24 config := bugs.Config{} 25 args := argumentList{"1"} // < 2 26 test := tester{} // from Pwd_test.go ; originally from Bug_test.go 27 test.Setup() 28 defer test.Teardown() 29 //bugDir := bugs.FitDirer(config) + bugs.TitleToDir(args[0]) 30 fitDir := bugs.FitDirer(config) 31 //bugDir := fitDir + bugs.TitleToDir("Test Bug") 32 //fmt.Print("bugDir ", bugDir, "\n") 33 34 expected := "Usage: .*" 35 runretitle("usage", args, config, expected, t) 36 37 args = argumentList{"bad", "bar"} // bad 38 expected = "Could not load issue: .*" 39 runretitle("bad", args, config, expected, t) 40 41 /* 42 this test fails on windows 43 removing write on directory doesn't cause the same error 44 TODO: finish making tests on Windows pass then redo this test 45 46 args = argumentList{"1", "Error Bug"} // rename err 47 // before chmod 48 //fi, _ := os.Open(string(fitDir)) 49 //stat, _ := fi.Stat() 50 //fmt.Println(dirDumpFI([]os.FileInfo{stat})) 51 //fmt.Println(dirDump(string(fitDir))) 52 //fmt.Printf("mode %v\n", stat.Mode()) 53 54 // chmod 500 temp parent directory, read and execute 55 err := os.Chmod(string(fitDir), 0500) // remove write permission 56 check(err) 57 // after chmod 58 //fi, _ = os.Open(string(fitDir)) 59 //stat, _ = fi.Stat() 60 //fmt.Println(dirDumpFI([]os.FileInfo{stat})) 61 //fmt.Println(dirDump(string(fitDir))) 62 //fmt.Printf("mode %v\n", stat.Mode()) 63 expected = "Moving .*\\nError moving directory\\n" 64 runretitle("rename err", args, config, expected, t) 65 */ 66 67 args = argumentList{"1", "Success Bug"} // good 68 // chmod 700 temp parent directory 69 err := os.Chmod(string(fitDir), 0700) // change 70 check(err) 71 expected = "Moving .*" 72 runretitle("good", args, config, expected, t) 73 }