Skip to content

Commit

Permalink
story(codeql): fully specify go version (z5labs#177)
Browse files Browse the repository at this point in the history
* build(issue-176): bump and fully qualify go version

* chore(docs): updated coverage badge.

* test(issue-176): increase test coverage

* chore(docs): updated coverage badge.

* build(issue-176): disable 1.22 coverage for now

* chore(docs): updated coverage badge.

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
Zaba505 and actions-user committed Apr 11, 2024
1 parent 9ac35f8 commit 934cbe1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 6 deletions.
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

0 comments on commit 934cbe1

Please sign in to comment.