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

[uptime] rewite to testable and add test #643

Merged
merged 1 commit into from Sep 7, 2022

Conversation

wafuwafu13
Copy link
Contributor

@wafuwafu13 wafuwafu13 commented Sep 2, 2022

Before rewrite check-uptime.go, can't test correctly because of reference.
Here is an example.

check-uptime-test.go

func TestCheckUptime(t *testing.T) {
	tests := []struct {
		args []string
		want checkers.Status
	}{
		{
			[]string{},
			checkers.OK,
		},
		{
			[]string{"-w", "-1"},
			checkers.OK,
		},
		{
			[]string{"-W", "-1"},
			checkers.WARNING,
		},
		{
			[]string{"-c", "-1"},
			checkers.OK,
		},
		{
			[]string{"-C", "-1"},
			checkers.CRITICAL,
		},
	}
	for _, tt := range tests {
		ckr := run(tt.args)
		assert.Equal(t, tt.want, ckr.Status)
	}
}

debug fmt.print(opts) in run function

~/Desktop/go-check-plugins/check-uptime/lib
$ go test -v
=== RUN   TestCheckUptime
{<nil> <nil> <nil> <nil> <nil> <nil>}
{<nil> 0xc0000a6aa8 <nil> <nil> <nil> <nil>}
{<nil> 0xc0000a6aa8 <nil> <nil> 0xc0000a6b30 <nil>}
{<nil> 0xc0000a6aa8 0xc0000a6bb8 <nil> 0xc0000a6b30 <nil>}
    check-uptime_test.go:38: 
                Error Trace:    /Users/wafuwafu13/Desktop/go-check-plugins/check-uptime/lib/check-uptime_test.go:38
                Error:          Not equal: 
                                expected: 0
                                actual  : 1
                Test:           TestCheckUptime
{<nil> 0xc0000a6aa8 0xc0000a6bb8 <nil> 0xc0000a6b30 0xc0000a6cb8}
--- FAIL: TestCheckUptime (0.00s)
FAIL
exit status 1
FAIL    github.com/mackerelio/go-check-plugins/check-uptime/lib 0.340s

Ref: https://github.com/mackerelio/go-check-plugins/blob/master/check-tcp/lib/check-tcp.go

@lufia lufia merged commit 1b71520 into mackerelio:master Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants