From d9591c2d33b0781a4ac77c1f0f4f9d9d41c20ae0 Mon Sep 17 00:00:00 2001 From: Sean Hacker Date: Thu, 13 Feb 2025 10:12:06 -0500 Subject: [PATCH 1/3] Optional startedAt defaults to now --- signal/signal.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/signal/signal.go b/signal/signal.go index a6dfb42..4845bc2 100644 --- a/signal/signal.go +++ b/signal/signal.go @@ -8,6 +8,7 @@ import ( "context" "encoding/base64" "fmt" + "time" "github.com/palantir/pkg/datetime" "github.com/palantir/pkg/safejson" @@ -22,10 +23,17 @@ type Signal struct { ErrorMessage *string `json:"error_message,omitempty" yaml:"error_message,omitempty"` } -func NewSignal(content any, startedAt datetime.DateTime, completedAt *datetime.DateTime, status int, errorMessage *string) Signal { +func NewSignal(content any, startedAt *datetime.DateTime, completedAt *datetime.DateTime, status int, errorMessage *string) Signal { + var startedAtTime datetime.DateTime + if startedAt == nil { + startedAtTime = datetime.DateTime(time.Now()) + } else { + startedAtTime = *startedAt + } + return Signal{ Content: content, - StartedAt: startedAt, + StartedAt: startedAtTime, CompletedAt: completedAt, Status: status, ErrorMessage: errorMessage, From 7ab6ceb7407ba5acbfdd71b4b322388936a506c2 Mon Sep 17 00:00:00 2001 From: Sean Hacker Date: Thu, 13 Feb 2025 10:16:38 -0500 Subject: [PATCH 2/3] Writer also takes pointer --- examples/signal/main.go | 6 +++--- signal/signal_test.go | 4 ++-- writer/writer.go | 2 +- writer/writer_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/signal/main.go b/examples/signal/main.go index 65ec99d..80bb2f7 100644 --- a/examples/signal/main.go +++ b/examples/signal/main.go @@ -31,13 +31,13 @@ func main() { jsonConfig := writer.NewOutputConfig(nil, writer.NewFormat(writer.JSON)) yamlConfig := writer.NewOutputConfig(nil, writer.NewFormat(writer.YAML)) - _ = writer.Write(report, signalConfig, startedAt, &startedAt, status, nil) + _ = writer.Write(report, signalConfig, &startedAt, &startedAt, status, nil) fmt.Println() fmt.Println() - _ = writer.Write(report, jsonConfig, startedAt, &startedAt, status, nil) + _ = writer.Write(report, jsonConfig, &startedAt, &startedAt, status, nil) fmt.Println() fmt.Println() - _ = writer.Write(report, yamlConfig, startedAt, &startedAt, status, nil) + _ = writer.Write(report, yamlConfig, &startedAt, &startedAt, status, nil) os.Exit(0) } diff --git a/signal/signal_test.go b/signal/signal_test.go index d2cdfef..1f57189 100644 --- a/signal/signal_test.go +++ b/signal/signal_test.go @@ -46,7 +46,7 @@ func TestSignal_EncodeContent(t *testing.T) { // Create a sample Signal instance now := datetime.DateTime(time.Now()) content := "Sample content" - signal := sig.NewSignal(content, now, nil, 200, nil) + signal := sig.NewSignal(content, &now, nil, 200, nil) // Encode the content err := signal.EncodeContent() @@ -66,7 +66,7 @@ func TestSignal_AddError(t *testing.T) { // Create a sample Signal instance now := datetime.DateTime(time.Now()) content := "Sample content" - signal := sig.NewSignal(content, now, nil, 200, nil) + signal := sig.NewSignal(content, &now, nil, 200, nil) // Add an error to the Signal err := errors.New("Sample error") diff --git a/writer/writer.go b/writer/writer.go index e723d0e..b811551 100644 --- a/writer/writer.go +++ b/writer/writer.go @@ -17,7 +17,7 @@ import ( func Write( report any, config OutputConfig, - startedAt datetime.DateTime, + startedAt *datetime.DateTime, completedAt *datetime.DateTime, status int, errorMessage *string, diff --git a/writer/writer_test.go b/writer/writer_test.go index cfe70f1..0dc0daf 100644 --- a/writer/writer_test.go +++ b/writer/writer_test.go @@ -80,7 +80,7 @@ func TestWrite(t *testing.T) { // Run test cases for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - err := writer.Write(tc.report, tc.config, tc.startedAt, tc.completedAt, tc.status, tc.errorMessage) + err := writer.Write(tc.report, tc.config, &tc.startedAt, tc.completedAt, tc.status, tc.errorMessage) if err != nil && err.Error() != tc.expectedErr.Error() { t.Errorf("Unexpected error while encoding content: %v", err) } From fedc2e145699f04c74b50776460cb85cb3e1da28 Mon Sep 17 00:00:00 2001 From: Sean Hacker Date: Thu, 13 Feb 2025 10:20:48 -0500 Subject: [PATCH 3/3] Fix verify --- .github/workflows/verify.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 0c5f6de..fcd867f 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -7,6 +7,10 @@ on: push: branches: - develop + +env: + GO_VERSION: "1.22.6" + jobs: verify: name: Verify @@ -14,5 +18,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true - name: Godel Verify run: ./godelw verify