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

story(codeql): fully specify go version #177

Merged
merged 9 commits into from
Apr 11, 2024
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion queue/sqs/sqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
111 changes: 111 additions & 0 deletions queue/sqs/sqsslog/sqslog_test.go
Original file line number Diff line number Diff line change
@@ -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
}
})
})
}
2 changes: 1 addition & 1 deletion queue/sqs/sqsslog/sqsslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down