github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Milestone_test.go (about) 1 package fitapp 2 3 import ( 4 "fmt" 5 bugs "github.com/grantbow/fit/issues" 6 "io/ioutil" 7 "os" 8 "regexp" 9 "testing" 10 ) 11 12 //var dops = bugs.Directory(os.PathSeparator) 13 //var sops = string(os.PathSeparator) 14 15 func runmiles(args argumentList, expected string, t *testing.T) { 16 config := bugs.Config{} 17 stdout, stderr := captureOutput(func() { 18 Milestone(args, config) 19 }, t) 20 if stderr != "" { 21 t.Error("Unexpected runmiles error: " + stderr) 22 } 23 re := regexp.MustCompile(expected) 24 matched := re.MatchString(stdout) 25 if !matched { 26 t.Error("Unexpected output on STDOUT for fitapp/Milestone_test") 27 fmt.Printf("Expected: %s\nGot: %s\n", expected, stdout) 28 } 29 } 30 31 func TestMilestone(t *testing.T) { 32 config := bugs.Config{} 33 config.FitDirName = "fit" 34 var gdir string 35 gdir, err := ioutil.TempDir("", "milestonegit") 36 pwd, _ := os.Getwd() 37 if err == nil { 38 os.Chdir(gdir) 39 // Hack to get around the fact that /tmp is a symlink on 40 // OS X, and it causes the directory checks to fail.. 41 gdir, _ = os.Getwd() 42 defer os.RemoveAll(gdir) 43 } else { 44 t.Error("Failed creating temporary directory for detect") 45 return 46 } 47 // Fake a git repo 48 os.Mkdir(".git", 0755) 49 // Make an issues Directory 50 os.Mkdir(config.FitDirName, 0755) 51 52 err = os.Setenv("FIT", gdir) 53 if err != nil { 54 t.Error("Could not set environment variable: " + err.Error()) 55 return 56 } 57 // bug 58 _, _ = captureOutput(func() { 59 Create(argumentList{"-n", "no_miles_bug"}, config) 60 }, t) 61 // before 62 runfind(argumentList{"milestone", "foo"}, "", t) 63 // add 64 runmiles(argumentList{"1", "foo"}, "", t) // no cmd as argument 65 // force it to test when runmiles doesn't work 66 //val := []byte("foo\n") 67 //fmt.Println(ioutil.WriteFile(string(gdir)+sops+config.FitDirName+sops+"no_miles_bug"+sops+"Milestone", []byte(val), 0644)) 68 // check 69 //bugDir, _ := ioutil.ReadDir(fmt.Sprintf("%s%s%s%sno_miles_bug", gdir, sops, config.FitDirName, sops)) 70 //fmt.Printf("readdir len %#v\n", len(bugDir)) 71 //fmt.Printf("readdir %#v\n", bugDir[0]) 72 //fmt.Printf("readdir %#v\n", bugDir[1]) 73 // after 74 file, err := ioutil.ReadFile(fmt.Sprintf("%s%s%s%sno_miles_bug%sMilestone", gdir, sops, config.FitDirName, sops, sops)) 75 if err != nil { 76 t.Error("Could not load Milestone file" + err.Error()) 77 } 78 if len(file) == 0 { 79 t.Error("Expected a Milestone file") 80 } 81 runfind(argumentList{"milestone", "foo"}, "Issue 1: no_miles_bug\n", t) 82 os.Chdir(pwd) 83 }