Skip to content

Commit

Permalink
Merge pull request #933 from gofiber/testify
Browse files Browse the repository at this point in the history
Add support for using stretchr/testify during tests
  • Loading branch information
ReneWerner87 committed Aug 23, 2023
2 parents 5253118 + 5ac0392 commit 4248a8d
Show file tree
Hide file tree
Showing 107 changed files with 1,158 additions and 1,634 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test-arangodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-azureblob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Install Azurite
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-badger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-bbolt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-couchbase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-dynamodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-etcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-memcache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-pebble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
redis:
- '6.x'
- '7.x'
Expand All @@ -41,7 +41,7 @@ jobs:
--tls-ca-cert-file ./redis/tests/tls/ca.crt&
- name: Setup Redis Cluster
uses: vishnudxb/redis-cluster@1.0.5
uses: vishnudxb/redis-cluster@1.0.8
with:
master1-port: 7000
master2-port: 7001
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-ristretto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
steps:
- name: Install MinIO
run: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-sqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
6 changes: 4 additions & 2 deletions arangodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ title: ArangoDB

A ArangoDB storage driver using `arangodb/go-driver` and [arangodb/go-driver](https://github.com/arangodb/go-driver).

**Note: Requires Go 1.19 and above**

### Table of Contents
- [Signatures](#signatures)
- [Installation](#installation)
Expand All @@ -35,13 +37,13 @@ go mod init github.com/<user>/<repo>
```
And then install the mysql implementation:
```bash
go get github.com/gofiber/storage/arangodb
go get github.com/gofiber/storage/arangodb/v2
```

### Examples
Import the storage package.
```go
import "github.com/gofiber/storage/arangodb"
import "github.com/gofiber/storage/arangodb/v2"
```

You can use the following possibilities to create a storage:
Expand Down
2 changes: 1 addition & 1 deletion arangodb/arangodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/http"
"github.com/gofiber/utils"
"github.com/gofiber/utils/v2"
)

// Storage interface that is implemented by storage providers
Expand Down
65 changes: 30 additions & 35 deletions arangodb/arangodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/gofiber/utils"
"github.com/stretchr/testify/require"
)

var testStore = New(Config{
Expand All @@ -18,7 +18,7 @@ func Test_ARANGODB_Set(t *testing.T) {
)

err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)
}

func Test_ARANGODB_Upsert(t *testing.T) {
Expand All @@ -28,10 +28,10 @@ func Test_ARANGODB_Upsert(t *testing.T) {
)

err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)
}

func Test_ARANGODB_Get(t *testing.T) {
Expand All @@ -41,11 +41,11 @@ func Test_ARANGODB_Get(t *testing.T) {
)

err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, val, result)
require.NoError(t, err)
require.Equal(t, val, result)
}

func Test_ARANGODB_Set_Expiration(t *testing.T) {
Expand All @@ -56,26 +56,23 @@ func Test_ARANGODB_Set_Expiration(t *testing.T) {
)

err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

time.Sleep(1100 * time.Millisecond)
}

func Test_ARANGODB_Get_Expired(t *testing.T) {
var (
key = "john"
)
key := "john"

result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, len(result) == 0)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Get_NotExist(t *testing.T) {

result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, len(result) == 0)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Delete(t *testing.T) {
Expand All @@ -85,54 +82,52 @@ func Test_ARANGODB_Delete(t *testing.T) {
)

err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

err = testStore.Delete(key)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, len(result) == 0)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Reset(t *testing.T) {
var (
val = []byte("doe")
)
val := []byte("doe")

err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

err = testStore.Reset()
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, len(result) == 0)
require.NoError(t, err)
require.Zero(t, len(result))

result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, len(result) == 0)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Non_UTF8(t *testing.T) {
val := []byte("0xF5")

err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err)
require.NoError(t, err)

result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, val, result)
require.NoError(t, err)
require.Equal(t, val, result)
}

func Test_ARANGODB_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close())
require.Nil(t, testStore.Close())
}

func Test_ARANGODB_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil)
require.True(t, testStore.Conn() != nil)
}
Loading

0 comments on commit 4248a8d

Please sign in to comment.