forked from z5labs/bedrock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
story(codeql): fully specify go version (z5labs#177)
* 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
1 parent
9ac35f8
commit 934cbe1
Showing
7 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters