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

Drop Go 1.20 support #34

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '=1.21'

- name: Format
run: test -z $(gofmt -l .)
Expand Down
4 changes: 2 additions & 2 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestReceive(t *testing.T) {

// We must capture the event
assert.NoError(t, err)
assert.True(t, len(data) >= 0)
assert.GreaterOrEqual(t, len(data), 1)
for _, d := range data {
assert.NotEqual(t, string(d.Data), "")
assert.NotEqual(t, string(d.Type), "")
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestSubscribe(t *testing.T) {

assert.Error(t, err)
assert.True(t, errors.Is(err, context.Canceled))
assert.True(t, elapsed >= 100*time.Millisecond)
assert.GreaterOrEqual(t, elapsed, 100*time.Millisecond)
}

func TestProcessEvent(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/thiagokokada/hyprland-go

retract v0.0.3 // Published too soon without proper event API consideration.

go 1.20
go 1.21
29 changes: 29 additions & 0 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package assert

import (
"cmp"
"reflect"
"testing"
)
Expand Down Expand Up @@ -71,3 +72,31 @@ func True(t *testing.T, got bool) {
t.Errorf("got: %#v, want: true", got)
}
}

func GreaterOrEqual[T cmp.Ordered](t *testing.T, got, want T) {
t.Helper()
if !(got >= want) {
t.Errorf("got: %#v, want: >=%#v", got, want)
}
}

func Greater[T cmp.Ordered](t *testing.T, got, want T) {
t.Helper()
if !(got > want) {
t.Errorf("got: %#v, want: >%#v", got, want)
}
}

func LessOrEqual[T cmp.Ordered](t *testing.T, got, want T) {
t.Helper()
if !(got <= want) {
t.Errorf("got: %#v, want: <=%#v", got, want)
}
}

func Less[T cmp.Ordered](t *testing.T, got, want T) {
t.Helper()
if !(got < want) {
t.Errorf("got: %#v, want: <%#v", got, want)
}
}
10 changes: 4 additions & 6 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,12 @@ func parseResponse(raw RawResponse) (response []Response, err error) {
func validateResponse(params []string, response []Response) ([]Response, error) {
// Empty response, something went terrible wrong
if len(response) == 0 {
return []Response{""}, ValidationError("empty response")
return []Response{}, ValidationError("empty response")
}

want := len(params)
if want == 0 {
// commands without parameters will have at least one return
want = 1
}
// commands without parameters will have at least one return
want := max(len(params), 1)

// we have a different number of requests and responses
if want != len(response) {
return response, ValidationError(fmt.Sprintf(
Expand Down
2 changes: 1 addition & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestValidateResponse(t *testing.T) {
wantErr bool
}{
// empty response should error
{genParams("param", 1), []Response{}, []Response{""}, true},
{genParams("param", 1), []Response{}, []Response{}, true},
// happy path, nil param
{nil, []Response{"ok"}, []Response{"ok"}, false},
// happy path, 1 param
Expand Down
Loading