Skip to content

Commit e1e09c6

Browse files
Add github actions
1 parent ec0f24b commit e1e09c6

3 files changed

Lines changed: 68 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test DBO
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
7+
pull_request:
8+
branches: [ master, develop ]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
# environment: testing
14+
15+
env:
16+
DB_USERNAME: root
17+
DB_PASSWORD: root
18+
DB_DATABASE: dbo_test
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Start MySQL
24+
run: sudo service mysql start
25+
26+
- name: Create MySQL Database
27+
run: mysql -u $DB_USERNAME -p$DB_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DB_DATABASE;"
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: '1.25'
33+
34+
- name: Clean test cache
35+
run: go clean -testcache
36+
37+
- name: Install modules
38+
run: go mod download
39+
40+
- name: Run DBO Tests
41+
run: go test ./tests -v

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
# dbo
1+
# DBO
2+
3+
The awesome DBO library for Golang, aims to bring developer friendliness to just about every project using the GORM package.
4+
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/Cyberpull/dbo)](https://goreportcard.com/report/github.com/Cyberpull/dbo)
6+
![Test Status](https://github.com/Cyberpull/dbo/actions/workflows/test.yml/badge.svg)
7+
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
8+
[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/Cyberpull/dbo?tab=doc)

tests/dbo_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"os"
45
"testing"
56

67
"github.com/Cyberpull/dbo"
@@ -28,15 +29,12 @@ func (x *DBOTestSuite) SetupSuite() {
2829
var err error
2930

3031
connector := dbo.NewConnector(dbo.Options{
31-
Driver: "mysql",
32-
Host: "localhost",
33-
Port: "3306",
34-
// DBName: os.Getenv("DB_DATABASE"),
35-
// Username: os.Getenv("DB_USERNAME"),
36-
// Password: os.Getenv("DB_PASSWORD"),
37-
DBName: "dbo_test",
38-
Username: "dbo_test",
39-
Password: "nonstop",
32+
Driver: "mysql",
33+
Host: "localhost",
34+
Port: "3306",
35+
DBName: env("DB_DATABASE", "dbo_test"),
36+
Username: env("DB_USERNAME", "dbo_test"),
37+
Password: env("DB_PASSWORD", "nonstop"),
4038
Config: &gorm.Config{
4139
CreateBatchSize: 3000,
4240
Logger: logger.Default.LogMode(logger.Silent),
@@ -209,6 +207,18 @@ func (x *DBOTestSuite) TestSuspendedPersons() {
209207

210208
// ===============================
211209

210+
func env(key string, defaultValue ...string) (value string) {
211+
value = os.Getenv(key)
212+
213+
if value == "" && len(defaultValue) > 0 {
214+
value = defaultValue[0]
215+
}
216+
217+
return
218+
}
219+
220+
// ===============================
221+
212222
func TestDBO(t *testing.T) {
213223
suite.Run(t, new(DBOTestSuite))
214224
}

0 commit comments

Comments
 (0)