From 92af12993d9e37c0a472d801a67d6a3d10602cdc Mon Sep 17 00:00:00 2001 From: Richard Carson Derr Date: Wed, 10 Apr 2024 23:18:07 -0400 Subject: [PATCH 1/6] build(issue-176): bump and fully qualify go version --- .github/workflows/codeql.yaml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index a49beae..13a06f6 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -30,7 +30,7 @@ jobs: # Custom Go version because of: https://github.com/github/codeql/issues/13992#issuecomment-1711721716 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22.0' - name: Initialize CodeQL uses: github/codeql-action/init@v3 diff --git a/go.mod b/go.mod index 8a7736c..cb5527a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/z5labs/bedrock -go 1.21 +go 1.22.0 require ( cloud.google.com/go/pubsub v1.37.0 From db266a418beefb76c7fe4536cfd7a87624860bda Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 11 Apr 2024 03:19:54 +0000 Subject: [PATCH 2/6] chore(docs): updated coverage badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7461f88..2c0764a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Reference](https://pkg.go.dev/badge/github.com/z5labs/bedrock.svg)](https://pkg.go.dev/github.com/z5labs/bedrock) [![Go Report Card](https://goreportcard.com/badge/github.com/z5labs/bedrock)](https://goreportcard.com/report/github.com/z5labs/bedrock) -![Coverage](https://img.shields.io/badge/Coverage-95.5%25-brightgreen) +![Coverage](https://img.shields.io/badge/Coverage-66.2%25-yellow) [![build](https://github.com/z5labs/bedrock/actions/workflows/build.yaml/badge.svg)](https://github.com/z5labs/bedrock/actions/workflows/build.yaml) **bedrock provides a minimal, modular and composable foundation for From 0cef290e294c5d2824f1c50a354715ae0394a27b Mon Sep 17 00:00:00 2001 From: Richard Carson Derr Date: Wed, 10 Apr 2024 23:50:36 -0400 Subject: [PATCH 3/6] test(issue-176): increase test coverage --- queue/sqs/sqs_test.go | 4 +- queue/sqs/sqsslog/sqslog_test.go | 111 +++++++++++++++++++++++++++++++ queue/sqs/sqsslog/sqsslog.go | 2 +- 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 queue/sqs/sqsslog/sqslog_test.go diff --git a/queue/sqs/sqs_test.go b/queue/sqs/sqs_test.go index f53286f..e1840df 100644 --- a/queue/sqs/sqs_test.go +++ b/queue/sqs/sqs_test.go @@ -243,7 +243,9 @@ func TestBatchDeleteProcessor_Process(t *testing.T) { t.Run("if sqs successfully deleted all messages", func(t *testing.T) { client := sqsBatchDeleteClientFunc(func(ctx context.Context, dmbi *sqs.DeleteMessageBatchInput, f ...func(*sqs.Options)) (*sqs.DeleteMessageBatchOutput, error) { - resp := &sqs.DeleteMessageBatchOutput{} + resp := &sqs.DeleteMessageBatchOutput{ + Successful: make([]types.DeleteMessageBatchResultEntry, 10), + } return resp, nil }) diff --git a/queue/sqs/sqsslog/sqslog_test.go b/queue/sqs/sqsslog/sqslog_test.go new file mode 100644 index 0000000..1c14429 --- /dev/null +++ b/queue/sqs/sqsslog/sqslog_test.go @@ -0,0 +1,111 @@ +// Copyright (c) 2024 Z5Labs and Contributors +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +package sqsslog + +import ( + "bytes" + "encoding/json" + "log/slog" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMessageId(t *testing.T) { + t.Run("will marshal as a string", func(t *testing.T) { + t.Run("if marshalling to json", func(t *testing.T) { + var buf bytes.Buffer + log := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) + + log.Info("hello", MessageId("1234")) + + var record struct { + MessageId string `json:"sqs_message_id"` + } + err := json.Unmarshal(buf.Bytes(), &record) + if !assert.Nil(t, err) { + return + } + if !assert.Equal(t, "1234", record.MessageId) { + return + } + }) + }) +} + +func TestMessageIds(t *testing.T) { + t.Run("will marshal as a list of strings", func(t *testing.T) { + t.Run("if marshalling to json", func(t *testing.T) { + var buf bytes.Buffer + log := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) + + ids := []string{"1234", "5678"} + log.Info("hello", MessageIds(ids)) + + var record struct { + MessageIds []string `json:"sqs_message_ids"` + } + err := json.Unmarshal(buf.Bytes(), &record) + if !assert.Nil(t, err) { + return + } + if !assert.Len(t, record.MessageIds, len(ids)) { + return + } + if !assert.Equal(t, ids, record.MessageIds) { + return + } + }) + }) +} + +func TestReceiptHandle(t *testing.T) { + t.Run("will marshal as a string", func(t *testing.T) { + t.Run("if marshalling to json", func(t *testing.T) { + var buf bytes.Buffer + log := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) + + log.Info("hello", ReceiptHandle("1234")) + + var record struct { + ReceiptHandle string `json:"sqs_receipt_handle"` + } + err := json.Unmarshal(buf.Bytes(), &record) + if !assert.Nil(t, err) { + return + } + if !assert.Equal(t, "1234", record.ReceiptHandle) { + return + } + }) + }) +} + +func TestMessageAttributes(t *testing.T) { + t.Run("will marshal as object", func(t *testing.T) { + t.Run("if marshalling to json", func(t *testing.T) { + var buf bytes.Buffer + log := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) + + attrs := map[string]string{"1234": "5678"} + log.Info("hello", MessageAttributes(attrs)) + + var record struct { + MessageAttributes map[string]string `json:"sqs_message_attributes"` + } + err := json.Unmarshal(buf.Bytes(), &record) + if !assert.Nil(t, err) { + return + } + if !assert.Len(t, record.MessageAttributes, len(attrs)) { + return + } + if !assert.Equal(t, attrs, record.MessageAttributes) { + return + } + }) + }) +} diff --git a/queue/sqs/sqsslog/sqsslog.go b/queue/sqs/sqsslog/sqsslog.go index fd0ad2f..cde3a6d 100644 --- a/queue/sqs/sqsslog/sqsslog.go +++ b/queue/sqs/sqsslog/sqsslog.go @@ -28,7 +28,7 @@ func ReceiptHandle(s string) slog.Attr { // MessageAttributes returns a slog.Attr for the SQS message attributes. func MessageAttributes(m map[string]string) slog.Attr { - attrs := make([]any, len(m)) + attrs := make([]any, 0, len(m)) for key, val := range m { attrs = append(attrs, slog.String(key, val)) } From 5b78e5a4db3ce816ed16dd8e3a2314ddea7b26ba Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 11 Apr 2024 03:51:05 +0000 Subject: [PATCH 4/6] chore(docs): updated coverage badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c0764a..f2578da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Reference](https://pkg.go.dev/badge/github.com/z5labs/bedrock.svg)](https://pkg.go.dev/github.com/z5labs/bedrock) [![Go Report Card](https://goreportcard.com/badge/github.com/z5labs/bedrock)](https://goreportcard.com/report/github.com/z5labs/bedrock) -![Coverage](https://img.shields.io/badge/Coverage-66.2%25-yellow) +![Coverage](https://img.shields.io/badge/Coverage-67.2%25-yellow) [![build](https://github.com/z5labs/bedrock/actions/workflows/build.yaml/badge.svg)](https://github.com/z5labs/bedrock/actions/workflows/build.yaml) **bedrock provides a minimal, modular and composable foundation for From c39bb7659d94790dfeac080abc45cfff9cd548a9 Mon Sep 17 00:00:00 2001 From: Richard Carson Derr Date: Thu, 11 Apr 2024 00:01:04 -0400 Subject: [PATCH 5/6] build(issue-176): disable 1.22 coverage for now --- .github/workflows/coverage.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index fbda55d..496abf9 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -24,8 +24,9 @@ jobs: go-version-file: 'go.mod' - name: Run Test + # re-enable new coverage flow once this issue is resolved, https://github.com/golang/go/issues/65570 run: | - go test -v ./... -covermode=count -coverprofile=coverage.out + GOEXPERIMENT=nocoverageredesign go test -v ./... -covermode=count -coverprofile=coverage.out go tool cover -func=coverage.out -o=coverage.out - name: Go Coverage Badge # Pass the `coverage.out` output to this action From 1777c512bca0fc9929790f591a25fdc11ccf19a5 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 11 Apr 2024 04:05:28 +0000 Subject: [PATCH 6/6] chore(docs): updated coverage badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2578da..649fbb5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Reference](https://pkg.go.dev/badge/github.com/z5labs/bedrock.svg)](https://pkg.go.dev/github.com/z5labs/bedrock) [![Go Report Card](https://goreportcard.com/badge/github.com/z5labs/bedrock)](https://goreportcard.com/report/github.com/z5labs/bedrock) -![Coverage](https://img.shields.io/badge/Coverage-67.2%25-yellow) +![Coverage](https://img.shields.io/badge/Coverage-96.2%25-brightgreen) [![build](https://github.com/z5labs/bedrock/actions/workflows/build.yaml/badge.svg)](https://github.com/z5labs/bedrock/actions/workflows/build.yaml) **bedrock provides a minimal, modular and composable foundation for