github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/cmd/qctkey/run_test.go (about) 1 2 package main 3 4 import ( 5 "fmt" 6 "os" 7 "testing" 8 9 "github.com/docker/docker/pkg/reexec" 10 "github.com/quickchainproject/quickchain/internal/cmdtest" 11 ) 12 13 type testEthkey struct { 14 *cmdtest.TestCmd 15 } 16 17 // spawns letkey with the given command line args. 18 func runEthkey(t *testing.T, args ...string) *testEthkey { 19 tt := new(testEthkey) 20 tt.TestCmd = cmdtest.NewTestCmd(t, tt) 21 tt.Run("letkey-test", args...) 22 return tt 23 } 24 25 func TestMain(m *testing.M) { 26 // Run the app if we've been exec'd as "letkey-test" in runEthkey. 27 reexec.Register("letkey-test", func() { 28 if err := app.Run(os.Args); err != nil { 29 fmt.Fprintln(os.Stderr, err) 30 os.Exit(1) 31 } 32 os.Exit(0) 33 }) 34 // check if we have been reexec'd 35 if reexec.Init() { 36 return 37 } 38 os.Exit(m.Run()) 39 }