Skip to content

Commit

Permalink
Update github actions to include more triggers + go versions; Update …
Browse files Browse the repository at this point in the history
…to io.util
  • Loading branch information
edocsss committed Jan 19, 2025
1 parent 08864a6 commit 88fa6e0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/full_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Full Test
on:
pull_request:
types: [synchronize]
types: [opened, synchronize]

env:
INTEGRATION_TEST_SPREADSHEET_ID: ${{ secrets.INTEGRATION_TEST_SPREADSHEET_ID }}
Expand All @@ -12,7 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.18.x']
# Cannot add all, it will create parallel jobs, might trigger Google Sheets API rate limit.
# Technically, we can change this to sequential job, but it will make the YML file longer.
go-version: ['1.23.x']

# This essentially means either the PR is just approved or it's edocsss who runs this.
if: github.event.review.state == 'approved' || github.event.pull_request.user.login == 'edocsss'
Expand All @@ -31,7 +33,9 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
# As there is only one Golang script being run.
# Faster if we don't cache as the cache is per commit anyway.
cache: false

- name: Golang version
run: go version
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.18.x']
go-version: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.x']

steps:
- uses: actions/checkout@v3
Expand All @@ -15,7 +15,9 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
# As there is only one Golang script being run.
# Faster if we don't cache as the cache is per commit anyway.
cache: false

- name: Golang version
run: go version
Expand Down
4 changes: 2 additions & 2 deletions internal/google/sheets/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -254,7 +254,7 @@ func (w *Wrapper) execQueryRows(
}
defer resp.Body.Close()

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return rawQueryRowsResult{}, err
}
Expand Down
14 changes: 14 additions & 0 deletions internal/google/store/gsheet_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/FreeLeh/GoFreeDB/internal/common"
"github.com/FreeLeh/GoFreeDB/internal/models"
"testing"
"time"

"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/stretchr/testify/assert"
Expand All @@ -30,24 +31,30 @@ func TestGoogleSheetKVStore_AppendOnly_Integration(t *testing.T) {
GoogleSheetKVStoreConfig{Mode: models.KVModeAppendOnly},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, kv.wrapper, spreadsheetID, []string{kv.sheetName, kv.scratchpadSheetName})
_ = kv.Close(context.Background())
}()

time.Sleep(time.Second)
value, err := kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test"))
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Equal(t, []byte("test"), value)
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Delete(context.Background(), "k1")
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)
Expand All @@ -72,27 +79,34 @@ func TestNewGoogleSheetKVStore_Default_Integration(t *testing.T) {
GoogleSheetKVStoreConfig{Mode: models.KVModeDefault},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, kv.wrapper, spreadsheetID, []string{kv.sheetName, kv.scratchpadSheetName})
_ = kv.Close(context.Background())
}()

time.Sleep(time.Second)
value, err := kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test"))
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Equal(t, []byte("test"), value)
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test2"))
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Delete(context.Background(), "k1")
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)
Expand Down
14 changes: 14 additions & 0 deletions internal/google/store/gsheet_kv_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/FreeLeh/GoFreeDB/internal/common"
"github.com/FreeLeh/GoFreeDB/internal/models"
"testing"
"time"

"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/stretchr/testify/assert"
Expand All @@ -30,24 +31,30 @@ func TestGoogleSheetKVStoreV2_AppendOnly_Integration(t *testing.T) {
GoogleSheetKVStoreV2Config{Mode: models.KVModeAppendOnly},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, kv.rowStore.wrapper, spreadsheetID, []string{kv.rowStore.sheetName})
_ = kv.Close(context.Background())
}()

time.Sleep(time.Second)
value, err := kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test"))
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Equal(t, []byte("test"), value)
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Delete(context.Background(), "k1")
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)
Expand All @@ -72,27 +79,34 @@ func TestNewGoogleSheetKVStoreV2_Default_Integration(t *testing.T) {
GoogleSheetKVStoreV2Config{Mode: models.KVModeDefault},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, kv.rowStore.wrapper, spreadsheetID, []string{kv.rowStore.sheetName})
_ = kv.Close(context.Background())
}()

time.Sleep(time.Second)
value, err := kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test"))
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Equal(t, []byte("test"), value)
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Set(context.Background(), "k1", []byte("test2"))
assert.Nil(t, err)

time.Sleep(time.Second)
err = kv.Delete(context.Background(), "k1")
assert.Nil(t, err)

time.Sleep(time.Second)
value, err = kv.Get(context.Background(), "k1")
assert.Nil(t, value)
assert.ErrorIs(t, err, models.ErrKeyNotFound)
Expand Down
16 changes: 16 additions & 0 deletions internal/google/store/gsheet_row_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/FreeLeh/GoFreeDB/internal/models"
"strconv"
"testing"
"time"

"github.com/FreeLeh/GoFreeDB/google/auth"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -37,33 +38,39 @@ func TestGoogleSheetRowStore_Integration(t *testing.T) {
GoogleSheetRowStoreConfig{Columns: []string{"name", "age", "dob"}},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, db.wrapper, spreadsheetID, []string{db.sheetName})
_ = db.Close(context.Background())
}()

var out []testPerson

time.Sleep(time.Second)
err = db.Select(&out, "name", "age").Offset(10).Limit(10).Exec(context.Background())
assert.Nil(t, err)
assert.Empty(t, out)

time.Sleep(time.Second)
err = db.Insert(
testPerson{"name1", 10, "1999-01-01"},
testPerson{"name2", 11, "2000-01-01"},
).Exec(context.Background())
assert.Nil(t, err)

// Nil type
time.Sleep(time.Second)
err = db.Insert(nil).Exec(context.Background())
assert.NotNil(t, err)

time.Sleep(time.Second)
err = db.Insert(testPerson{
Name: "name3",
Age: 9007199254740992,
DOB: "2001-01-01",
}).Exec(context.Background())
assert.Nil(t, err)

time.Sleep(time.Second)
err = db.Update(map[string]interface{}{"name": "name4"}).
Where("age = ?", 10).
Exec(context.Background())
Expand All @@ -73,6 +80,8 @@ func TestGoogleSheetRowStore_Integration(t *testing.T) {
{"name2", 11, "2000-01-01"},
{"name3", 9007199254740992, "2001-01-01"},
}

time.Sleep(time.Second)
err = db.Select(&out, "name", "age", "dob").
Where("name = ? OR name = ?", "name2", "name3").
OrderBy([]models.ColumnOrderBy{{"name", models.OrderByAsc}}).
Expand All @@ -81,12 +90,14 @@ func TestGoogleSheetRowStore_Integration(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expected, out)

time.Sleep(time.Second)
count, err := db.Count().
Where("name = ? OR name = ?", "name2", "name3").
Exec(context.Background())
assert.Nil(t, err)
assert.Equal(t, uint64(2), count)

time.Sleep(time.Second)
err = db.Delete().Where("name = ?", "name4").Exec(context.Background())
assert.Nil(t, err)
}
Expand All @@ -110,25 +121,30 @@ func TestGoogleSheetRowStore_Integration_EdgeCases(t *testing.T) {
GoogleSheetRowStoreConfig{Columns: []string{"name", "age", "dob"}},
)
defer func() {
time.Sleep(time.Second)
deleteSheet(t, db.wrapper, spreadsheetID, []string{db.sheetName})
_ = db.Close(context.Background())
}()

// Non-struct types
time.Sleep(time.Second)
err = db.Insert([]interface{}{"name3", 12, "2001-01-01"}).Exec(context.Background())
assert.NotNil(t, err)

// IEEE 754 unsafe integer
time.Sleep(time.Second)
err = db.Insert([]interface{}{"name3", 9007199254740993, "2001-01-01"}).Exec(context.Background())
assert.NotNil(t, err)

// IEEE 754 unsafe integer
time.Sleep(time.Second)
err = db.Insert(
testPerson{"name1", 10, "1999-01-01"},
testPerson{"name2", 11, "2000-01-01"},
).Exec(context.Background())
assert.Nil(t, err)

time.Sleep(time.Second)
err = db.Update(map[string]interface{}{"name": "name4", "age": int64(9007199254740993)}).
Exec(context.Background())
assert.NotNil(t, err)
Expand Down

0 comments on commit 88fa6e0

Please sign in to comment.