From 5f59f90f9c3d6c1060fe23c93311d29afdccf5d2 Mon Sep 17 00:00:00 2001 From: soulteary Date: Mon, 9 Jan 2023 22:02:57 +0800 Subject: [PATCH] fix: Fix 1.19 incompatibilities --- droppriv_nope.go | 1 + droppriv_unix.go | 1 + internal/hook/hook_test.go | 53 ++++++++++++++-------------- internal/middleware/logger.go | 4 +-- internal/pidfile/mkdirall.go | 1 + internal/pidfile/mkdirall_windows.go | 1 + internal/pidfile/pidfile_darwin.go | 1 + internal/pidfile/pidfile_unix.go | 1 + signals.go | 1 + signals_windows.go | 1 + webhook_test.go | 2 +- 11 files changed, 38 insertions(+), 29 deletions(-) diff --git a/droppriv_nope.go b/droppriv_nope.go index 3c6a518..f274e96 100644 --- a/droppriv_nope.go +++ b/droppriv_nope.go @@ -1,3 +1,4 @@ +//go:build linux || windows // +build linux windows package main diff --git a/droppriv_unix.go b/droppriv_unix.go index c292e7d..ff5533c 100644 --- a/droppriv_unix.go +++ b/droppriv_unix.go @@ -1,3 +1,4 @@ +//go:build !windows && !linux // +build !windows,!linux package main diff --git a/internal/hook/hook_test.go b/internal/hook/hook_test.go index e9f29e4..fc9d677 100644 --- a/internal/hook/hook_test.go +++ b/internal/hook/hook_test.go @@ -294,14 +294,14 @@ var hookParseJSONParametersTests = []struct { rheaders, rquery, rpayload map[string]interface{} ok bool }{ - {[]Argument{Argument{"header", "a", "", false}}, map[string]interface{}{"A": `{"b": "y"}`}, nil, nil, map[string]interface{}{"A": map[string]interface{}{"b": "y"}}, nil, nil, true}, - {[]Argument{Argument{"url", "a", "", false}}, nil, map[string]interface{}{"a": `{"b": "y"}`}, nil, nil, map[string]interface{}{"a": map[string]interface{}{"b": "y"}}, nil, true}, - {[]Argument{Argument{"payload", "a", "", false}}, nil, nil, map[string]interface{}{"a": `{"b": "y"}`}, nil, nil, map[string]interface{}{"a": map[string]interface{}{"b": "y"}}, true}, - {[]Argument{Argument{"header", "z", "", false}}, map[string]interface{}{"Z": `{}`}, nil, nil, map[string]interface{}{"Z": map[string]interface{}{}}, nil, nil, true}, + {[]Argument{{"header", "a", "", false}}, map[string]interface{}{"A": `{"b": "y"}`}, nil, nil, map[string]interface{}{"A": map[string]interface{}{"b": "y"}}, nil, nil, true}, + {[]Argument{{"url", "a", "", false}}, nil, map[string]interface{}{"a": `{"b": "y"}`}, nil, nil, map[string]interface{}{"a": map[string]interface{}{"b": "y"}}, nil, true}, + {[]Argument{{"payload", "a", "", false}}, nil, nil, map[string]interface{}{"a": `{"b": "y"}`}, nil, nil, map[string]interface{}{"a": map[string]interface{}{"b": "y"}}, true}, + {[]Argument{{"header", "z", "", false}}, map[string]interface{}{"Z": `{}`}, nil, nil, map[string]interface{}{"Z": map[string]interface{}{}}, nil, nil, true}, // failures - {[]Argument{Argument{"header", "z", "", false}}, map[string]interface{}{"Z": ``}, nil, nil, map[string]interface{}{"Z": ``}, nil, nil, false}, // empty string - {[]Argument{Argument{"header", "y", "", false}}, map[string]interface{}{"X": `{}`}, nil, nil, map[string]interface{}{"X": `{}`}, nil, nil, false}, // missing parameter - {[]Argument{Argument{"string", "z", "", false}}, map[string]interface{}{"Z": ``}, nil, nil, map[string]interface{}{"Z": ``}, nil, nil, false}, // invalid argument source + {[]Argument{{"header", "z", "", false}}, map[string]interface{}{"Z": ``}, nil, nil, map[string]interface{}{"Z": ``}, nil, nil, false}, // empty string + {[]Argument{{"header", "y", "", false}}, map[string]interface{}{"X": `{}`}, nil, nil, map[string]interface{}{"X": `{}`}, nil, nil, false}, // missing parameter + {[]Argument{{"string", "z", "", false}}, map[string]interface{}{"Z": ``}, nil, nil, map[string]interface{}{"Z": ``}, nil, nil, false}, // invalid argument source } func TestHookParseJSONParameters(t *testing.T) { @@ -326,9 +326,9 @@ var hookExtractCommandArgumentsTests = []struct { value []string ok bool }{ - {"test", []Argument{Argument{"header", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"test", "z"}, true}, + {"test", []Argument{{"header", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"test", "z"}, true}, // failures - {"fail", []Argument{Argument{"payload", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"fail", ""}, false}, + {"fail", []Argument{{"payload", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"fail", ""}, false}, } func TestHookExtractCommandArguments(t *testing.T) { @@ -351,20 +351,21 @@ func TestHookExtractCommandArguments(t *testing.T) { // we test both cases where the name of the data is used as the name of the // env key & the case where the hook definition sets the env var name to a // fixed value using the envname construct like so:: -// [ -// { -// "id": "push", -// "execute-command": "bb2mm", -// "command-working-directory": "/tmp", -// "pass-environment-to-command": -// [ -// { -// "source": "entire-payload", -// "envname": "PAYLOAD" -// }, -// ] -// } -// ] +// +// [ +// { +// "id": "push", +// "execute-command": "bb2mm", +// "command-working-directory": "/tmp", +// "pass-environment-to-command": +// [ +// { +// "source": "entire-payload", +// "envname": "PAYLOAD" +// }, +// ] +// } +// ] var hookExtractCommandArgumentsForEnvTests = []struct { exec string args []Argument @@ -375,14 +376,14 @@ var hookExtractCommandArgumentsForEnvTests = []struct { // successes { "test", - []Argument{Argument{"header", "a", "", false}}, + []Argument{{"header", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"HOOK_a=z"}, true, }, { "test", - []Argument{Argument{"header", "a", "MYKEY", false}}, + []Argument{{"header", "a", "MYKEY", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{"MYKEY=z"}, true, @@ -390,7 +391,7 @@ var hookExtractCommandArgumentsForEnvTests = []struct { // failures { "fail", - []Argument{Argument{"payload", "a", "", false}}, + []Argument{{"payload", "a", "", false}}, map[string]interface{}{"A": "z"}, nil, nil, []string{}, false, diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index 899dd1c..b4a2d0d 100644 --- a/internal/middleware/logger.go +++ b/internal/middleware/logger.go @@ -39,13 +39,13 @@ type LogEntry struct { } // Write constructs and writes the final log entry. -func (l *LogEntry) Write(status, totalBytes int, elapsed time.Duration) { +func (l *LogEntry) Write(status int, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { rid := GetReqID(l.req.Context()) if rid != "" { fmt.Fprintf(l.buf, "[%s] ", rid) } - fmt.Fprintf(l.buf, "%03d | %s | %s | ", status, humanize.IBytes(uint64(totalBytes)), elapsed) + fmt.Fprintf(l.buf, "%03d | %s | %s | ", status, humanize.IBytes(uint64(bytes)), elapsed) l.buf.WriteString(l.req.Host + " | " + l.req.Method + " " + l.req.RequestURI) log.Print(l.buf.String()) } diff --git a/internal/pidfile/mkdirall.go b/internal/pidfile/mkdirall.go index 1491366..4a5983f 100644 --- a/internal/pidfile/mkdirall.go +++ b/internal/pidfile/mkdirall.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package pidfile diff --git a/internal/pidfile/mkdirall_windows.go b/internal/pidfile/mkdirall_windows.go index 0194de2..1dc7975 100644 --- a/internal/pidfile/mkdirall_windows.go +++ b/internal/pidfile/mkdirall_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package pidfile diff --git a/internal/pidfile/pidfile_darwin.go b/internal/pidfile/pidfile_darwin.go index 2cd001a..5531152 100644 --- a/internal/pidfile/pidfile_darwin.go +++ b/internal/pidfile/pidfile_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package pidfile diff --git a/internal/pidfile/pidfile_unix.go b/internal/pidfile/pidfile_unix.go index 1bf5221..32e9ad0 100644 --- a/internal/pidfile/pidfile_unix.go +++ b/internal/pidfile/pidfile_unix.go @@ -1,3 +1,4 @@ +//go:build !windows && !darwin // +build !windows,!darwin package pidfile diff --git a/signals.go b/signals.go index 23f0a74..d6c0c96 100644 --- a/signals.go +++ b/signals.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package main diff --git a/signals_windows.go b/signals_windows.go index e7a2a1d..5418700 100644 --- a/signals_windows.go +++ b/signals_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package main diff --git a/webhook_test.go b/webhook_test.go index 50fef52..0dec049 100755 --- a/webhook_test.go +++ b/webhook_test.go @@ -47,7 +47,7 @@ func TestStaticParams(t *testing.T) { ResponseMessage: "success", CaptureCommandOutput: true, PassArgumentsToCommand: []hook.Argument{ - hook.Argument{Source: "string", Name: "passed"}, + {Source: "string", Name: "passed"}, }, }