|
@@ -7,10 +7,13 @@
|
|
|
package svc_test
|
|
package svc_test
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "fmt"
|
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
|
+ "math/rand"
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
|
+ "strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
@@ -86,8 +89,10 @@ func TestExample(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
defer s.Close()
|
|
defer s.Close()
|
|
|
|
|
|
|
|
|
|
+ args := []string{"is", "manual-started", fmt.Sprintf("%d", rand.Int())}
|
|
|
|
|
+
|
|
|
testState(t, s, svc.Stopped)
|
|
testState(t, s, svc.Stopped)
|
|
|
- err = s.Start("is", "manual-started")
|
|
|
|
|
|
|
+ err = s.Start(args...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("Start(%s) failed: %s", s.Name, err)
|
|
t.Fatalf("Start(%s) failed: %s", s.Name, err)
|
|
|
}
|
|
}
|
|
@@ -115,4 +120,16 @@ func TestExample(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("Delete failed: %s", err)
|
|
t.Fatalf("Delete failed: %s", err)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ cmd := `Get-Eventlog -LogName Application -Newest 100` +
|
|
|
|
|
+ ` | Where Source -eq "myservice"` +
|
|
|
|
|
+ ` | Select -first 10` +
|
|
|
|
|
+ ` | Format-table -HideTableHeaders -property ReplacementStrings`
|
|
|
|
|
+ out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatalf("powershell failed: %v\n%v", err, string(out))
|
|
|
|
|
+ }
|
|
|
|
|
+ if want := strings.Join(append([]string{name}, args...), "-"); !strings.Contains(string(out), want) {
|
|
|
|
|
+ t.Errorf("%q string does not contain %q", string(out), want)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|