Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes tests and vet in go1.7 #11

Merged
merged 1 commit into from
Dec 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: go
go:
- 1.6
- 1.7

os:
- linux
Expand Down
6 changes: 3 additions & 3 deletions monitor/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ func (c *check) SetMonitored(monitored bool) {
func newCheck(id string, kind string) interface {
Checkable
} {
check := check{Timeout: 120 * time.Second, ID: id, logger: log.DummyLogger()}
check := &check{Timeout: 120 * time.Second, ID: id, logger: log.DummyLogger()}
switch kind {
case "process":
return &ProcessCheck{check: check}
default:
return &check
return check
}
}

Expand Down Expand Up @@ -549,7 +549,7 @@ func (c *ProcessCheck) Status() (str string) {

// ProcessCheck defines a service type check
type ProcessCheck struct {
check
*check
Group string
PidFile string
StartProgram *Command
Expand Down
12 changes: 5 additions & 7 deletions monitor/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (ds *dummyService) setTimesStarted(t int) {
}

func newDummyService(id string) *dummyService {
s := dummyService{ProcessCheck: ProcessCheck{check: check{ID: id}}}
s := dummyService{ProcessCheck: ProcessCheck{check: &check{ID: id}}}
s.startTime = 5 * time.Millisecond
s.stopTime = 5 * time.Millisecond
s.doError = false
Expand Down Expand Up @@ -134,14 +134,12 @@ func (dc *dummyCheck) setTimesCalled(t int) {
}

func newDummyCheck(id string) *dummyCheck {
c := &dummyCheck{}
c.ID = id
return c
return &dummyCheck{ProcessCheck: ProcessCheck{check: &check{ID: id}}}
}

func TestCheckOnceOneSimultaneousInvocationPerObject(t *testing.T) {
t.Parallel()
dc := &dummyCheck{}
dc := newDummyCheck("dummy")
dc.Initialize(Opts{})

dc.setWaitTime(20 * time.Millisecond)
Expand All @@ -165,11 +163,11 @@ func TestCheckOnceOneSimultaneousInvocationPerObject(t *testing.T) {

func TestCheckOnceTwoChecksWithSameId(t *testing.T) {
t.Parallel()
dc1 := &dummyCheck{}
dc1 := newDummyCheck("dummy")
dc1.Initialize(Opts{})
dc1.setWaitTime(20 * time.Millisecond)

dc2 := &dummyCheck{}
dc2 := newDummyCheck("dummy")
dc2.Initialize(Opts{})
dc2.setWaitTime(20 * time.Millisecond)

Expand Down
19 changes: 9 additions & 10 deletions monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestUpdateDatabase(t *testing.T) {
db := app.database
assert.Len(t, db.Keys(), 0)
for _, id := range ids {
app.AddCheck(&ProcessCheck{check: check{ID: id}})
app.AddCheck(&ProcessCheck{check: &check{ID: id}})
}
db.Deserialize()
assert.Len(t, db.Keys(), 0)
Expand All @@ -143,7 +143,7 @@ func TestUpdateDatabase(t *testing.T) {

// Deregisters unknown checks
app.checks = nil
app.AddCheck(&ProcessCheck{check: check{ID: "foo"}})
app.AddCheck(&ProcessCheck{check: &check{ID: "foo"}})
app.UpdateDatabase()
db.Deserialize()
assert.Equal(t, db.Keys(), []string{"foo"})
Expand All @@ -157,7 +157,7 @@ func TestFindCheck(t *testing.T) {
Checkable
})
for _, id := range ids {
ch := &ProcessCheck{check: check{ID: id}}
ch := &ProcessCheck{check: &check{ID: id}}
checks[id] = ch
app.AddCheck(ch)
}
Expand All @@ -176,7 +176,7 @@ func TestAddCheck(t *testing.T) {
require.NoError(t, err)
logger := app.logger
for _, id := range ids {
ch := &ProcessCheck{check: check{ID: id}}
ch := &ProcessCheck{check: &check{ID: id}}
assert.NoError(t, app.AddCheck(ch))
// When adding the check, the app set it up to use its logger
// TODO: Maybe this should not be the case, so a check can be registered
Expand All @@ -185,7 +185,7 @@ func TestAddCheck(t *testing.T) {
}

for _, id := range ids {
ch := &ProcessCheck{check: check{ID: id}}
ch := &ProcessCheck{check: &check{ID: id}}
tu.AssertErrorMatch(t, app.AddCheck(ch), regexp.MustCompile("Service name conflict,.*already defined"))
}
}
Expand Down Expand Up @@ -603,8 +603,7 @@ func TestSummaryText(t *testing.T) {
app, err := New(Config{})
require.NoError(t, err)
// With no checks
assert.Regexp(t, regexp.MustCompile("^\\s*Uptime 0\\s*$"), app.SummaryText())

assert.Regexp(t, regexp.MustCompile("^\\s*Uptime 0s?\\s*$"), app.SummaryText())
dc1 := newDummyCheck("dummy1")
// Make it to be running
f, _ := sb.Write(sb.TempFile(), fmt.Sprintf("%d", syscall.Getpid()))
Expand All @@ -616,7 +615,7 @@ func TestSummaryText(t *testing.T) {
app.AddCheck(dc2)

assert.Regexp(t, regexp.MustCompile(
"^\\s*Uptime 0\\s*\n\nProcess\\s+dummy1\\s+Running\nProcess\\s+dummy2\\s+Stopped\n$",
"^\\s*Uptime 0s?\\s*\n\nProcess\\s+dummy1\\s+Running\nProcess\\s+dummy2\\s+Stopped\n$",
), app.SummaryText())
}

Expand All @@ -643,12 +642,12 @@ func TestStatusText(t *testing.T) {
statusTextHeaderPattern+`\s*Process\s+'dummy1'\s*
\s*status\s+Running
\s*pid\s*\d+
\s*uptime\s*\d+
\s*uptime\s*\d+s?
\s*monitoring status\s*monitored

Process\s+'dummy2'\s*
\s*status\s+Stopped
\s*uptime\s*0
\s*uptime\s*0s?
\s*monitoring status\s*monitored
`,
), app.StatusText())
Expand Down