github.com/darelread/dasdsadasddas@v1.3.0/app_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "os" 6 "strings" 7 "testing" 8 ) 9 10 func TestRun(t *testing.T) { 11 os.Args = []string{"dot-github"} 12 o := &bytes.Buffer{} 13 e := &bytes.Buffer{} 14 app := &App{o, e} 15 app.Run() 16 if e.String() != "" { 17 t.Errorf("Some error was output while command running") 18 } 19 } 20 21 func TestRunWithFlags(t *testing.T) { 22 os.Args = []string{"dot-github", "-issue", "-pullrequest", "-contributing"} 23 o := &bytes.Buffer{} 24 e := &bytes.Buffer{} 25 app := &App{o, e} 26 app.Run() 27 if e.String() != "" { 28 t.Errorf("Some error was output while command running") 29 } 30 } 31 32 func TestInvalidFlag(t *testing.T) { 33 os.Args = []string{"dot-github", "-unknown"} 34 o := &bytes.Buffer{} 35 e := &bytes.Buffer{} 36 app := &App{o, e} 37 app.Run() 38 if !strings.Contains(e.String(), "Usage:") { 39 t.Errorf("Command must show usage on invalid flag") 40 } 41 } 42 43 func TestHelpFlag(t *testing.T) { 44 os.Args = []string{"dot-github", "-help"} 45 o := &bytes.Buffer{} 46 e := &bytes.Buffer{} 47 app := &App{o, e} 48 app.Run() 49 if !strings.Contains(e.String(), "Usage:") { 50 t.Errorf("Command must show usage on -help flag") 51 } 52 } 53 54 func TestVersionFlag(t *testing.T) { 55 os.Args = []string{"dot-github", "-version"} 56 o := &bytes.Buffer{} 57 e := &bytes.Buffer{} 58 app := &App{o, e} 59 app.Run() 60 if !strings.Contains(o.String(), ".") { 61 t.Errorf("Command must show version on -version flag") 62 } 63 64 }