service: use flag package to correctly run su test
This commit is contained in:
+1
-2
@@ -3,10 +3,9 @@ go_import_path: github.com/kardianos/service
|
|||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.6.x
|
|
||||||
- 1.7.x
|
|
||||||
- 1.8.x
|
- 1.8.x
|
||||||
- 1.9.x
|
- 1.9.x
|
||||||
|
- "1.10"
|
||||||
- master
|
- master
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
|||||||
+12
-10
@@ -8,6 +8,7 @@
|
|||||||
package service_test
|
package service_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@@ -23,17 +24,18 @@ import (
|
|||||||
const runAsServiceArg = "RunThisAsService"
|
const runAsServiceArg = "RunThisAsService"
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
if len(os.Args) == 2 {
|
reportDir := flag.String("su.reportDir", "", "")
|
||||||
|
runAsService := flag.Bool("su.runAsService", false, "")
|
||||||
|
flag.Parse()
|
||||||
|
if !*runAsService {
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
} else if len(os.Args) == 4 && os.Args[2] == runAsServiceArg {
|
|
||||||
reportDir := os.Args[3]
|
|
||||||
writeReport(reportDir, "call")
|
|
||||||
runService()
|
|
||||||
writeReport(reportDir, "finished")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
if len(*reportDir) == 0 {
|
||||||
log.Fatalf("Invalid arguments: %v", os.Args)
|
log.Fatal("missing su.reportDir argument")
|
||||||
|
}
|
||||||
|
writeReport(*reportDir, "call")
|
||||||
|
runService()
|
||||||
|
writeReport(*reportDir, "finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInstallRunRestartStopRemove(t *testing.T) {
|
func TestInstallRunRestartStopRemove(t *testing.T) {
|
||||||
@@ -168,7 +170,7 @@ func mustNewRunAsService(
|
|||||||
) service.Service {
|
) service.Service {
|
||||||
sc := &service.Config{
|
sc := &service.Config{
|
||||||
Name: "go_service_test",
|
Name: "go_service_test",
|
||||||
Arguments: []string{"-test.v=true", runAsServiceArg, reportDir},
|
Arguments: []string{"-test.v=true", "-su.runAsService", "-su.reportDir", reportDir},
|
||||||
}
|
}
|
||||||
s, err := service.New(p, sc)
|
s, err := service.New(p, sc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user