Skip to content
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
6 changes: 6 additions & 0 deletions .github/linters/betterleaks-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ title = "betterleaks config extensions"
[extend]
useDefault = true

[allowlist]
description = "Ignore test certificates and keys"
paths = [
'''^tests/integration/certs/'''
]

[[rules]]
id = "generic-api-key"

Expand Down
9 changes: 9 additions & 0 deletions .github/linters/betterleaks-ignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests/integration/certs/server/rabbitmq_combined.pem:private-key:21
tests/integration/certs/server/rabbitmq.key:private-key:1
tests/integration/certs/server/arke.key:private-key:1
tests/integration/certs/testca/private/ca_private_key.pem:private-key:1
doc/design/client-publish-consume.md:generic-password:124
Makefile:generic-password:187
tools/anarkey/example-config-queue.json:generic-password:9
tools/anarkey/example-config-stream.json:generic-password:9
examples/all_in_one/main.go:generic-password:46
10 changes: 6 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ on:
- main
- release-*
env:
GO_VERSION: 1.26.6
GO_VERSION: 1.27
ARTIFACT_DIR: ./artifacts
LINT_DIR: ./.github/linters
COV_DIR: ./artifacts/cov
BETTERLEAKS_VERSION: 1.1.2
BETTERLEAKS_VERSION: 1.9.0

jobs:
lint-other-files:
Expand Down Expand Up @@ -86,7 +86,9 @@ jobs:
url="https://github.com/betterleaks/betterleaks/releases/download/v${{ env.BETTERLEAKS_VERSION }}/betterleaks_${{ env.BETTERLEAKS_VERSION }}_${os}_${arch}.tar.gz"
echo "Downloading betterleaks from $url"
curl -sSL "$url" | tar zxf - > "$outfile"
"$outfile" git --config ./.github/linters/betterleaks-config.toml -v
"$outfile" dir . -v \
--config ./.github/linters/betterleaks-config.toml \
--gitleaks-ignore-path ./.github/linters/betterleaks-ignore.txt

go-lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -117,7 +119,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a
with:
version: v2.11
version: v2.15
args: --config=${{ env.LINT_DIR }}/golangci-config.yaml --allow-parallel-runners

go-test:
Expand Down
8 changes: 6 additions & 2 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func run(ctx context.Context) {
if err != nil {
util.Logger.Fatal(i18n.CPUProfileError, err)
}
defer f.Close()
defer func() {
_ = f.Close()
}()
if err := pprof.StartCPUProfile(f); err != nil {
util.Logger.Fatal(i18n.CPUProfileError, err)
}
Expand All @@ -49,7 +51,9 @@ func run(ctx context.Context) {
if err != nil {
util.Logger.Fatal(i18n.MemProfileError, err)
}
defer f.Close()
defer func() {
_ = f.Close()
}()
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
util.Logger.Fatal(i18n.MemProfileError, err)
Expand Down
18 changes: 11 additions & 7 deletions cmd/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func testHealth(port int) error {
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()
c := pb.NewHealthzClient(conn)
ctx := context.Background()
_, err = c.Check(ctx)
Expand All @@ -39,8 +41,7 @@ func TestMonitorProcessStats(t *testing.T) {
assert.Nil(t, err)
cancel()
}()
os.Setenv(arke.EnvPort, "50058")
defer os.Unsetenv(arke.EnvPort)
t.Setenv(arke.EnvPort, "50058")
run(ctx)
}

Expand All @@ -49,11 +50,15 @@ func TestRunWithCPUAndMemProfile(t *testing.T) {

cpuFile, err := os.CreateTemp(tmpDir, "cpuprofile-*.prof")
assert.Nil(t, err)
cpuFile.Close()
defer func() {
_ = cpuFile.Close()
}()

memFile, err := os.CreateTemp(tmpDir, "memprofile-*.prof")
assert.Nil(t, err)
memFile.Close()
defer func() {
_ = memFile.Close()
}()

*cpuprofile = cpuFile.Name()
*memprofile = memFile.Name()
Expand All @@ -69,8 +74,7 @@ func TestRunWithCPUAndMemProfile(t *testing.T) {
assert.Nil(t, err)
cancel()
}()
os.Setenv(arke.EnvPort, "50061")
defer os.Unsetenv(arke.EnvPort)
t.Setenv(arke.EnvPort, "50061")

run(ctx)

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.46.0
go.opentelemetry.io/otel/sdk v1.46.0
go.opentelemetry.io/otel/trace v1.46.0
golang.org/x/text v0.42.0
golang.org/x/text v0.43.0
golang.org/x/time v0.16.0
google.golang.org/grpc v1.83.2
google.golang.org/protobuf v1.36.12
Expand Down Expand Up @@ -79,10 +79,10 @@ require (
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/net v0.58.0 // indirect
golang.org/x/net v0.61.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/term v0.45.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/term v0.47.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -192,17 +194,24 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=
golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w=
golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM=
golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE=
golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 h1:ax2KzoSRIZU/M0cIxri3pKxy99vniH1PVxWC6si/eZI=
Expand Down
24 changes: 15 additions & 9 deletions i18n/message_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ type getLocaleFileTestCase struct {
expectedFiles []string
}

const testValue2 = "value2"
const (
localeEnUS = "en-US"
testValue2 = "value2"
localeDeDE = "de-DE"
multipleParamsID = "multiple_params"
)

func TestGetLocaleFiles(t *testing.T) {
filePrefix := messageFilePrefix

cases := []getLocaleFileTestCase{
{
filePrefix: filePrefix,
locale: "en-US",
locale: localeEnUS,
expectedFiles: []string{
fmt.Sprintf("resources/%s_en_US.properties", filePrefix),
fmt.Sprintf("resources/%s_en.properties", filePrefix),
Expand Down Expand Up @@ -73,7 +79,7 @@ func TestGetLocaleFiles(t *testing.T) {
},
{
filePrefix: filePrefix,
locale: "de-DE",
locale: localeDeDE,
expectedFiles: []string{
fmt.Sprintf("resources/%s_de_DE.properties", filePrefix),
fmt.Sprintf("resources/%s_de.properties", filePrefix),
Expand Down Expand Up @@ -238,10 +244,10 @@ func TestT(t *testing.T) {
}()
bundle = &propertiesBundle{
messages: map[string]string{
"no_params": "This is a test message.",
"one_param": "Hello, {0}!",
"repeated_param": "Value: {0}, Again: {0}",
"multiple_params": "First: {0}, Second: {1}, Third: {2}, First again: {0}",
"no_params": "This is a test message.",
"one_param": "Hello, {0}!",
"repeated_param": "Value: {0}, Again: {0}",
multipleParamsID: "First: {0}, Second: {1}, Third: {2}, First again: {0}",
},
}
tests := []struct {
Expand Down Expand Up @@ -270,7 +276,7 @@ func TestT(t *testing.T) {
},
{
name: "multiple parameters",
messageID: "multiple_params",
messageID: multipleParamsID,
args: []interface{}{"A", "B", "C"},
want: "First: A, Second: B, Third: C, First again: A",
},
Expand All @@ -282,7 +288,7 @@ func TestT(t *testing.T) {
},
{
name: "extra arguments",
messageID: "multiple_params",
messageID: multipleParamsID,
args: []interface{}{"A", "B", "C", "D"},
want: "First: A, Second: B, Third: C, First again: A",
},
Expand Down
24 changes: 9 additions & 15 deletions i18n/oslocale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,37 @@ func TestArgsInit(t *testing.T) {
},
{
name: "cli args override",
Lang: "en-US",
Lang: localeEnUS,
LcAll: "",
args: []string{"a", "--locale", "zh"},
expected: "zh",
},
{
name: EnvLang,
Lang: "en-US",
Lang: localeEnUS,
LcAll: "",
args: []string{"a"},
expected: "en-US",
expected: localeEnUS,
},
{
name: EnvLcAll,
Lang: "",
LcAll: "de-DE",
LcAll: localeDeDE,
args: []string{"a"},
expected: "de-DE",
expected: localeDeDE,
},
{
name: EnvLcAll + " priority",
Lang: "zh-Hans",
LcAll: "de-DE",
LcAll: localeDeDE,
args: []string{"a"},
expected: "de-DE",
expected: localeDeDE,
},
}
for _, c := range cases {
oldLang := os.Getenv(EnvLang)
oldLCAll := os.Getenv(EnvLcAll)
defer func() {
os.Setenv(EnvLang, oldLang)
os.Setenv(EnvLcAll, oldLCAll)
}()
t.Run(c.name, func(t *testing.T) {
os.Setenv(EnvLang, c.Lang)
os.Setenv(EnvLcAll, c.LcAll)
t.Setenv(EnvLang, c.Lang)
t.Setenv(EnvLcAll, c.LcAll)
os.Args = c.args
l10Messages = nil
SystemLocale = ""
Expand Down
25 changes: 11 additions & 14 deletions i18n/oslocale_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,33 @@
package i18n

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDetectIETF_LC_ALL(t *testing.T) {
os.Setenv(EnvLcAll, "fr_FR.UTF-8")
t.Setenv(EnvLcAll, "fr_FR.UTF-8")
result, _ := DetectIETF()
assert.Equal(t, result, "fr-FR")
}

func TestDetectIETF_LANG(t *testing.T) {
os.Setenv(EnvLang, "fr_FR.UTF-8")
t.Setenv(EnvLang, "fr_FR.UTF-8")
result, _ := DetectIETF()
assert.Equal(t, result, "fr-FR")
}

func TestDetectIETF_Blank(t *testing.T) {
os.Setenv(EnvLcAll, "")
os.Setenv(EnvLang, "")
t.Setenv(EnvLcAll, "")
t.Setenv(EnvLang, "")
result, _ := DetectIETF()
assert.Equal(t, result, "")
}

func TestStandardInit(t *testing.T) {
os.Unsetenv(EnvLang)
os.Unsetenv(EnvLcAll)
t.Setenv(EnvLang, "")
t.Setenv(EnvLcAll, "")
locale, _ := DetectIETF()
if locale == "" {
locale = defaultLanguage
Expand All @@ -43,23 +42,21 @@ func TestStandardInit(t *testing.T) {
}

func TestLangC(t *testing.T) {
os.Unsetenv(EnvLcAll)
os.Setenv(EnvLang, "C")
t.Setenv(EnvLcAll, "")
t.Setenv(EnvLang, "C")
locale, err := DetectIETF()
assert.NotNil(t, err)
assert.Equal(t, "", locale)

os.Setenv(EnvLang, "C.UTF-8")
defer os.Unsetenv(EnvLang)
t.Setenv(EnvLang, "C.UTF-8")
locale, err = DetectIETF()
assert.NotNil(t, err)
assert.Equal(t, "", locale)
}

func TestInvalidLang(t *testing.T) {
os.Unsetenv(EnvLcAll)
os.Setenv(EnvLang, "invalid")
defer os.Unsetenv(EnvLang)
t.Setenv(EnvLcAll, "")
t.Setenv(EnvLang, "invalid")
locale, err := DetectIETF()
assert.NotNil(t, err)
assert.Equal(t, "", locale)
Expand Down
Loading
Loading