github.com/perlchild/DBShield@v0.0.0-20170924200059-c888d9e40e13/main_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "flag" 6 "io/ioutil" 7 "os" 8 "testing" 9 ) 10 11 func TestEveryThing(t *testing.T) { 12 usage(true) 13 14 os.Args = []string{os.Args[0], "-k", "-c", "conf/dbshield.yml"} 15 main() 16 17 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 18 os.Args = []string{os.Args[0], "-purge", "-c", "conf/dbshield.yml"} 19 main() 20 21 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 22 os.Args = []string{os.Args[0], "-l", "-c", "conf/invalid.yml"} 23 main() 24 25 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 26 os.Args = []string{os.Args[0], "-l", "-c", "conf/dbshield.yml"} 27 main() 28 29 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 30 os.Args = []string{os.Args[0], "-a", "-c", "conf/dbshield.yml"} 31 main() 32 33 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 34 os.Args = []string{os.Args[0], "-r", "XYZ", "-c", "conf/dbshield.yml"} 35 main() 36 37 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 38 os.Args = []string{os.Args[0], "-version"} 39 main() 40 41 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 42 os.Args = []string{os.Args[0], "-h"} 43 main() 44 45 flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 46 dat, err := ioutil.ReadFile("conf/dbshield.yml") 47 if err != nil { 48 t.Fatal(err) 49 } 50 path := os.TempDir() + "/tempconfig.yml" 51 dat = bytes.Replace(dat, []byte("logPath: "), []byte("logPath: "+os.TempDir()+" #"), 1) 52 err = ioutil.WriteFile(path, dat, 0600) 53 if err != nil { 54 t.Fatal(err) 55 } 56 os.Args = []string{os.Args[0], "-c", path} 57 defer func() { 58 if r := recover(); r == nil { 59 t.Error("Expected panic") 60 } 61 }() 62 main() 63 }