surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
240 stars 66 forks source link

Update tests to use 'testing' package to replace panic. #30

Closed ffrizzo closed 2 years ago

ffrizzo commented 2 years ago

Testing packages provide better error messages than use panic on tests.

Before

❯ go test -v -cover ./...
=== RUN   TestUnmarshalRaw
--- FAIL: TestUnmarshalRaw (0.00s)
panic: dial tcp 127.0.0.1:8000: connect: connection refused [recovered]
        panic: dial tcp 127.0.0.1:8000: connect: connection refused

goroutine 19 [running]:
testing.tRunner.func1.2({0x1045a4820, 0x14000092000})
        /opt/homebrew/Cellar/go/1.19.2/libexec/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
        /opt/homebrew/Cellar/go/1.19.2/libexec/src/testing/testing.go:1399 +0x378
panic({0x1045a4820, 0x14000092000})
        /opt/homebrew/Cellar/go/1.19.2/libexec/src/runtime/panic.go:884 +0x204
github.com/surrealdb/surrealdb%2ego_test.TestUnmarshalRaw(0x0?)
        /Volumes/Files/workspaces/opensource/surrealdb/surrealdb.go/db_test.go:237 +0x6e0
testing.tRunner(0x14000106ea0, 0x1045d5ed8)
        /opt/homebrew/Cellar/go/1.19.2/libexec/src/testing/testing.go:1446 +0x10c
created by testing.(*T).Run
        /opt/homebrew/Cellar/go/1.19.2/libexec/src/testing/testing.go:1493 +0x300
FAIL    github.com/surrealdb/surrealdb.go       0.524s
?       github.com/surrealdb/surrealdb.go/internal/websocket    [no test files]
FAIL

After

❯ go test -v -cover ./... -count=1
=== RUN   TestDelete
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestDelete (0.00s)
=== RUN   TestCreate
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestCreate (0.00s)
=== RUN   TestSelect
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestSelect (0.00s)
=== RUN   TestUpdate
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestUpdate (0.00s)
=== RUN   TestUnmarshalRaw
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestUnmarshalRaw (0.00s)
=== RUN   TestModify
    db_test.go:26: dial tcp 127.0.0.1:8000: connect: connection refused
--- FAIL: TestModify (0.00s)
FAIL
coverage: 3.4% of statements
FAIL    github.com/surrealdb/surrealdb.go       0.160s
?       github.com/surrealdb/surrealdb.go/internal/websocket    [no test files]
FAIL