github.com/release-engineering/exodus-rsync@v1.11.2/cmd/exodus-rsync/main_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 "testing" 8 ) 9 10 // Tests the main entry point to the exodus-rsync command. 11 // 12 // Note that this package is just an exiting wrapper around non-exiting 13 // functions under the internal packages. This test is mainly to get 14 // the coverage to 100%, while more meaningful tests are implemented 15 // elsewhere in the relevant packages. 16 func Test_main(t *testing.T) { 17 // Main function reads from os.Args, overwrite during the test. 18 oldArgs := os.Args 19 defer func() { 20 os.Args = oldArgs 21 }() 22 23 // Main function is expected to exit successfully when running with --help. 24 // Exit is translated to a panic during test. Recover it to allow the test 25 // to pass. 26 defer func() { 27 why := fmt.Sprint(recover()) 28 // This is the only valid reason to panic. 29 if !strings.Contains(why, "os.Exit(0)") { 30 t.Fatal(why) 31 } 32 }() 33 34 // Main should exit successfully when invoked with --help. 35 os.Args = []string{"exodus-rsync", "--help"} 36 main() 37 }