Skip to content

Commit

Permalink
refactor(tests): use massert everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Nov 9, 2023
1 parent a018477 commit 2bdf66a
Show file tree
Hide file tree
Showing 44 changed files with 273 additions and 306 deletions.
4 changes: 2 additions & 2 deletions binaries/binaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

func tmpDir(t *testing.T) string {
Expand Down Expand Up @@ -66,5 +66,5 @@ func TestFetch_withCache(t *testing.T) {
func TestFetch_relativeDir(t *testing.T) {
actual := FetchNative(".")
expected := fmt.Errorf("toDir must be absolute")
assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
}
4 changes: 2 additions & 2 deletions runtime/types/raw/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

func TestBool_UnmarshalJSON(t *testing.T) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestBool_UnmarshalJSON(t *testing.T) {
if err := json.Unmarshal(tt.args.b, &v); (err != nil) != tt.wantErr {
t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(t, tt.expected, v)
massert.Equal(t, tt.expected, v)
})
}
}
7 changes: 3 additions & 4 deletions test/databases/mysql/json/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestJSON(t *testing.T) {
},
}

assert.Equal(t, expected, created)
massert.Equal(t, expected, created)

actual, err := client.User.FindFirst(
User.JSON.Path("$.attr"),
Expand All @@ -62,7 +61,7 @@ func TestJSON(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}}
for _, tt := range tests {
Expand Down
19 changes: 9 additions & 10 deletions test/databases/mysql/raw/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestRaw(t *testing.T) {
BoolOpt: &bFalse,
}}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}, {
name: "raw query with parameter",
Expand Down Expand Up @@ -184,7 +183,7 @@ func TestRaw(t *testing.T) {
BoolOpt: &bFalse,
}}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}, {
name: "raw query with multiple parameters",
Expand Down Expand Up @@ -250,7 +249,7 @@ func TestRaw(t *testing.T) {
BoolOpt: &bFalse,
}}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}, {
name: "raw query count",
Expand Down Expand Up @@ -304,7 +303,7 @@ func TestRaw(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, "2", actual[0].Count)
massert.Equal(t, "2", actual[0].Count)
},
}, {
name: "insert into",
Expand All @@ -319,7 +318,7 @@ func TestRaw(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, 1, result.Count)
massert.Equal(t, 1, result.Count)
},
}, {
name: "update",
Expand Down Expand Up @@ -351,14 +350,14 @@ func TestRaw(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, 1, result.Count)
massert.Equal(t, 1, result.Count)

result, err = client.Prisma.ExecuteRaw("update `User` set email = 'abc' where id = ?", "non-existing").Exec(ctx)
if err != nil {
t.Fatalf("fail %s", err)
}

assert.Equal(t, 0, result.Count)
massert.Equal(t, 0, result.Count)
},
}, {
name: "raw query with time parameter",
Expand Down Expand Up @@ -428,7 +427,7 @@ func TestRaw(t *testing.T) {
BoolOpt: &bFalse,
}}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}}
for _, tt := range tests {
Expand Down
33 changes: 16 additions & 17 deletions test/databases/postgresql/array/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand Down Expand Up @@ -49,7 +48,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "query by full items",
Expand Down Expand Up @@ -81,7 +80,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "query by empty items",
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "query by nil items",
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "query by empty var items",
Expand Down Expand Up @@ -179,7 +178,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "create one",
Expand All @@ -199,7 +198,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "create one empty",
Expand All @@ -219,7 +218,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "create one empty nil var",
Expand All @@ -240,7 +239,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "create one empty non-nil var",
Expand All @@ -261,7 +260,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "read filter has",
Expand Down Expand Up @@ -293,7 +292,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "read filter has every",
Expand Down Expand Up @@ -325,7 +324,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "read filter has some",
Expand Down Expand Up @@ -357,7 +356,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "read filter is empty",
Expand Down Expand Up @@ -389,7 +388,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
name: "write filter",
Expand Down Expand Up @@ -423,7 +422,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}, {
// this test ensures that all additional filters are picked out in the case, e.g. `In`
Expand Down Expand Up @@ -456,7 +455,7 @@ func TestArrays(t *testing.T) {
},
}

assert.Equal(t, expected, user)
massert.Equal(t, expected, user)
},
}}
for _, tt := range tests {
Expand Down
11 changes: 5 additions & 6 deletions test/databases/postgresql/json/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestJSON(t *testing.T) {
},
}

assert.Equal(t, expected, created)
massert.Equal(t, expected, created)

actual, err := client.User.FindFirst(
User.JSON.Path([]string{"attr"}),
Expand All @@ -71,7 +70,7 @@ func TestJSON(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}, {
name: "json filter nested",
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestJSON(t *testing.T) {
},
}

assert.Equal(t, expected, created)
massert.Equal(t, expected, created)

actual, err := client.User.FindFirst(
User.JSON.Path([]string{"obj", "nested_attr"}),
Expand All @@ -129,7 +128,7 @@ func TestJSON(t *testing.T) {
t.Fatalf("fail %s", err)
}

assert.Equal(t, expected, actual)
massert.Equal(t, expected, actual)
},
}}
for _, tt := range tests {
Expand Down
6 changes: 3 additions & 3 deletions test/databases/sqlite/checks_nested/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/steebchen/prisma-client-go/test"
db "github.com/steebchen/prisma-client-go/test/databases/sqlite/checks_nested/prisma"
"github.com/stretchr/testify/assert"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand All @@ -36,14 +36,14 @@ func TestSqliteChecksNested(t *testing.T) {
}
`},
run: func(t *testing.T, client *db.PrismaClient, ctx cx) {
assert.Equal(t, "file:custom/dev.db", db.SchemaDatasourceURL)
massert.Equal(t, "file:custom/dev.db", db.SchemaDatasourceURL)

users, err := client.User.FindMany().Exec(ctx)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, 1, len(users))
massert.Equal(t, 1, len(users))
},
}}
for _, tt := range tests {
Expand Down
6 changes: 3 additions & 3 deletions test/databases/sqlite/checks_path/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/steebchen/prisma-client-go/test"
"github.com/stretchr/testify/assert"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
Expand All @@ -35,14 +35,14 @@ func TestSqliteChecks(t *testing.T) {
}
`},
run: func(t *testing.T, client *PrismaClient, ctx cx) {
assert.Equal(t, "file:dev.db", schemaDatasourceURL)
massert.Equal(t, "file:dev.db", schemaDatasourceURL)

users, err := client.User.FindMany().Exec(ctx)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, 1, len(users))
massert.Equal(t, 1, len(users))
},
}}
for _, tt := range tests {
Expand Down
Loading

0 comments on commit 2bdf66a

Please sign in to comment.