Skip to content

Commit

Permalink
Merge pull request #34 from thiagokokada/drop-go-120-support
Browse files Browse the repository at this point in the history
Drop Go 1.20 support
  • Loading branch information
thiagokokada authored Sep 4, 2024
2 parents 768532f + 5c6e728 commit cb10aac
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
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

0 comments on commit cb10aac

Please sign in to comment.