Karena database integration test memerlukan proses pembuatan temporary docker image, proses test akan berjalan lebih lambat dibanding unit test lainnya.
Merupakan praktek umum, untuk memisahkan integration test dengan unit test lainnya.
Untuk memisahkan digunakan build tag. Buka file pkg/repository/dbrepo/users_postgres_test.go, lalu tambahkan tag pada awal file (sebelum keyword package).
//go:build integration
package dbrepo
import (
"database/sql"
"fmt"
"log"
...
... the rest of code is truncated
...
Jika kita jalankan perintah test pada direktori pkg/repository/dbrepo, akan tampil log tidak ada test files.
go test -v .
? webapp/pkg/repository/dbrepo [no test files]
Jika kita ingin jalankan integration test, gunakan option tags=nama_tag, dalam hal ini nama tag adalah integration.
$ go test -v -tags=integration .
go test -v -tags=integration .
=== RUN Test_pingDB
--- PASS: Test_pingDB (0.00s)
=== RUN TestPostgresDBRepoInsertUser
--- PASS: TestPostgresDBRepoInsertUser (0.24s)
=== RUN TestPostgresDBRepoAllUsers
--- PASS: TestPostgresDBRepoAllUsers (0.24s)
=== RUN TestPostgresDBRepoGetUser
--- PASS: TestPostgresDBRepoGetUser (0.01s)
=== RUN TestPostgresDBRepoGetUserByEmail
--- PASS: TestPostgresDBRepoGetUserByEmail (0.00s)
=== RUN TestPostgresDBRepoUpdateUser
--- PASS: TestPostgresDBRepoUpdateUser (0.01s)
=== RUN TestPostgresDBRepoDeleteUser
--- PASS: TestPostgresDBRepoDeleteUser (0.00s)
=== RUN TestPostgresDBRepoResetPassword
--- PASS: TestPostgresDBRepoResetPassword (0.46s)
=== RUN TestPostgresDBRepoInsertUserImage
--- PASS: TestPostgresDBRepoInsertUserImage (0.01s)
PASS
ok webapp/pkg/repository/dbrepo 6.450s