Skip to content

Commit

Permalink
Update golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Nov 12, 2024
1 parent aded2d6 commit d603d25
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ jobs:
- name: Run lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
version: v1.62
args: --timeout 5m
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters-settings:
- require-error
- error-nil
- formatter
- encoded-compare
revive:
rules:
- name: var-naming
Expand Down
6 changes: 3 additions & 3 deletions database/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestLogger(t *testing.T) {

l.Info(context.Background(), "message %d", 1)

assert.Regexp(t, regexp.MustCompile(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`), buf.String())
assert.Regexp(t, `{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`, buf.String())
})

t.Run("Warn", func(t *testing.T) {
Expand All @@ -66,7 +66,7 @@ func TestLogger(t *testing.T) {

l.Warn(context.Background(), "message %d", 1)

assert.Regexp(t, regexp.MustCompile(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"WARN","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`), buf.String())
assert.Regexp(t, `{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"WARN","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`, buf.String())
})

t.Run("Error", func(t *testing.T) {
Expand All @@ -84,7 +84,7 @@ func TestLogger(t *testing.T) {

l.Error(context.Background(), "message %d", 1)

assert.Regexp(t, regexp.MustCompile(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`), buf.String())
assert.Regexp(t, `{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"message 1"}\n`, buf.String())
})

t.Run("Trace", func(t *testing.T) {
Expand Down
32 changes: 16 additions & 16 deletions log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func TestWriter(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s","details":{"host":"192\.0\.2\.1","username":"-","time":"2020-03-23T13:58:26\.371Z","method":"GET","uri":"/log","proto":"HTTP/1\.1","status":200,"length":13}}\n`,
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 13`),
)),
),
buffer.String(),
)
})
Expand Down Expand Up @@ -90,10 +90,10 @@ func TestWriter(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s","details":{"host":"192\.0\.2\.1","username":"-","time":"2020-03-23T13:58:26\.371Z","method":"GET","uri":"/log","proto":"HTTP/1\.1","status":200,"length":13}}\n`,
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 13`),
)),
),
buffer.String(),
)
})
Expand Down Expand Up @@ -128,10 +128,10 @@ func TestWriter(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s","details":{"host":"192\.0\.2\.1","username":"-","time":"2020-03-23T13:58:26\.371Z","method":"GET","uri":"/log","proto":"HTTP/1\.1","status":200,"length":13}}\n`,
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 13`),
)),
),
buffer.String(),
)
assert.True(t, child.closed)
Expand Down Expand Up @@ -167,10 +167,10 @@ func TestWriter(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s"}\n`, // Same thing but details are omitted
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 13`),
)),
),
buffer.String(),
)
assert.True(t, child.closed)
Expand All @@ -192,10 +192,10 @@ func TestMiddleware(t *testing.T) {
})
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s","details":{"host":"192\.0\.2\.1","username":"-","time":"2020-03-23T13:58:26\.371Z","method":"GET","uri":"/log","proto":"HTTP/1\.1","status":200,"length":11}}\n`,
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 11`),
)),
),
buffer.String(),
)
})
Expand All @@ -214,10 +214,10 @@ func TestMiddleware(t *testing.T) {
})
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s"}\n`, // Same thing but details are omitted
regexp.QuoteMeta(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 11`),
)),
),
buffer.String(),
)
})
Expand All @@ -244,12 +244,12 @@ func TestMiddleware(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s","details":{"host":"192\.0\.2\.1","username":"-","time":"2020-03-23T13:58:26\.371Z","method":"GET","uri":"/log","proto":"HTTP/1\.1","status":200,"length":11,"referrer":"%s","userAgent":"%s"}}\n`,
regexp.QuoteMeta(fmt.Sprintf(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 11 \"%s\" \"%s\"`, referrer, userAgent)),
regexp.QuoteMeta(referrer),
regexp.QuoteMeta(userAgent),
)),
),
buffer.String(),
)
})
Expand All @@ -275,10 +275,10 @@ func TestMiddleware(t *testing.T) {
_ = httpResponse.Body.Close()
assert.Equal(t, http.StatusOK, httpResponse.StatusCode)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"INFO","source":{"function":".+","file":".+","line":\d+},"msg":"%s"}\n`, // Same thing but details are omitted
regexp.QuoteMeta(fmt.Sprintf(`192.0.2.1 - - [23/Mar/2020:13:58:26 +0000] \"GET \"/log\" HTTP/1.1\" 200 11 \"%s\" \"%s\"`, referrer, userAgent)),
)),
),
buffer.String(),
)
})
Expand Down
12 changes: 6 additions & 6 deletions middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func TestRecoveryMiddleware(t *testing.T) {
return
}
assert.Equal(t, []error{panicErr}, returnedErr.Unwrap())
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(returnedErr.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(returnedErr.StackFrames().String())))),
)),
),
logBuffer.String(),
)
assert.Equal(t, http.StatusInternalServerError, response.status)
Expand Down Expand Up @@ -163,10 +163,10 @@ func TestRecoveryMiddleware(t *testing.T) {
return
}
assert.Equal(t, []error{&runtime.PanicNilError{}}, returnedErr.Unwrap())
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(returnedErr.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(returnedErr.StackFrames().String())))),
)),
),
logBuffer.String(),
)
assert.Equal(t, http.StatusInternalServerError, response.status)
Expand Down Expand Up @@ -197,10 +197,10 @@ func TestRecoveryMiddleware(t *testing.T) {
return
}
assert.Len(t, returnedErr.Unwrap(), 1)
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(returnedErr.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(returnedErr.StackFrames().String())))),
)),
),
logBuffer.String(),
)
assert.Equal(t, http.StatusInternalServerError, response.status)
Expand Down
12 changes: 6 additions & 6 deletions response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ func TestResponse(t *testing.T) {
}
assert.Equal(t, []error{err}, e.Unwrap())
assert.Equal(t, http.StatusInternalServerError, resp.status)
assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(e.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(e.StackFrames().String())))),
)),
),
logBuffer.String(),
)
})
Expand Down Expand Up @@ -475,10 +475,10 @@ func TestResponse(t *testing.T) {
assert.Equal(t, "application/json; charset=utf-8", res.Header.Get("Content-Type"))
assert.Equal(t, "{\"error\":\"custom error\"}\n", string(body))

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(e.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(e.StackFrames().String())))),
)),
),
logBuffer.String(),
)
})
Expand Down Expand Up @@ -507,10 +507,10 @@ func TestResponse(t *testing.T) {
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Equal(t, "forbidden", string(body))

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s","trace":%s}\n`,
regexp.QuoteMeta(e.Error()), regexp.QuoteMeta(string(lo.Must(json.Marshal(e.StackFrames().String())))),
)),
),
logBuffer.String(),
)
})
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ func TestErrLogWriter(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, len(message), n)

assert.Regexp(t, regexp.MustCompile(
assert.Regexp(t,
fmt.Sprintf(`{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}((\+\d{2}:\d{2})|Z)?","level":"ERROR","source":{"function":".+","file":".+","line":\d+},"msg":"%s"}\n`,
regexp.QuoteMeta(message),
)),
),
buf.String(),
)
}

0 comments on commit d603d25

Please sign in to comment.