Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactor to allow use of vscode latest features

goenning5ae20dd2dc06
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 7e026e1d7..13c26fb6c 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -21,5 +21,14 @@
".cover": true,
"cover.out": true
},
- "vsicons.presets.angular": true
+ "vsicons.presets.angular": true,
+ "go.coverageOptions": "showBothCoveredAndUncoveredCode",
+ "go.coverOnSave": true,
+ "go.testEnvVars": {
+ "GO_ENV": "test",
+ "HOST_MODE": "multi",
+ "DATABASE_URL": "postgres://wechy_test:wechy_test-pw@localhost:5566/wechy_test?sslmode=disable",
+ "AUTH_ENDPOINT": "http://login.test.canhearyou.com:3000",
+ "JWT_SECRET": "I1$$MplJ-007A8]G#RE0VVfvv:I~o6+2yA0@)>2|{K$Z1628z9;w7lAsZ"
+ }
}
\ No newline at end of file
diff --git a/app/pkg/dbx/dbx.go b/app/pkg/dbx/dbx.go
index 04fa3b919..afd4745cb 100644
--- a/app/pkg/dbx/dbx.go
+++ b/app/pkg/dbx/dbx.go
@@ -7,6 +7,7 @@ import (
"reflect"
"github.com/WeCanHearYou/wechy/app/pkg/env"
+ "github.com/mattes/migrate/migrate"
//required
_ "github.com/lib/pq"
@@ -202,3 +203,18 @@ func (db Database) load(path string) {
panic(err)
}
}
+
+// Migrate the database to latest verion
+func (db Database) Migrate() {
+ fmt.Printf("Running migrations... \n")
+ errors, ok := migrate.UpSync(env.MustGet("DATABASE_URL"), env.Path("/migrations"))
+ if !ok {
+ for i, err := range errors {
+ fmt.Printf("Error #%d: %s.\n", i, err)
+ }
+
+ panic("Migrations failed.")
+ } else {
+ fmt.Printf("Migrations finished with success.\n")
+ }
+}
diff --git a/app/pkg/dbx/dbx_test.go b/app/pkg/dbx/dbx_test.go
index 023679fd3..8492af7f1 100644
--- a/app/pkg/dbx/dbx_test.go
+++ b/app/pkg/dbx/dbx_test.go
@@ -1,9 +1,11 @@
package dbx_test
import (
+ "os"
"testing"
"github.com/WeCanHearYou/wechy/app/pkg/dbx"
+ _ "github.com/mattes/migrate/driver/postgres"
. "github.com/onsi/gomega"
)
@@ -24,6 +26,15 @@ type tenant struct {
Name string `db:"name"`
}
+func TestMain(m *testing.M) {
+ db, _ := dbx.New()
+ db.Migrate()
+ db.Close()
+
+ code := m.Run()
+ os.Exit(code)
+}
+
func TestBind_SimpleStruct(t *testing.T) {
RegisterTestingT(t)
db, _ := dbx.New()
diff --git a/app/storage/postgres/setup_test.go b/app/storage/postgres/setup_test.go
new file mode 100644
index 000000000..20768fb7d
--- /dev/null
+++ b/app/storage/postgres/setup_test.go
@@ -0,0 +1,18 @@
+package postgres_test
+
+import (
+ "os"
+ "testing"
+
+ "github.com/WeCanHearYou/wechy/app/pkg/dbx"
+ _ "github.com/mattes/migrate/driver/postgres"
+)
+
+func TestMain(m *testing.M) {
+ db, _ := dbx.New()
+ db.Migrate()
+ db.Close()
+
+ code := m.Run()
+ os.Exit(code)
+}
diff --git a/main.go b/main.go
index be91cfaa2..b050ad44e 100644
--- a/main.go
+++ b/main.go
@@ -8,8 +8,6 @@ import (
"github.com/WeCanHearYou/wechy/app/pkg/env"
"github.com/WeCanHearYou/wechy/app/pkg/oauth"
"github.com/WeCanHearYou/wechy/app/storage/postgres"
- _ "github.com/mattes/migrate/driver/postgres"
- mig "github.com/mattes/migrate/migrate"
"fmt"
)
@@ -17,31 +15,15 @@ import (
var buildtime string
var version = "0.2.0"
-func migrate() {
- fmt.Printf("Running migrations... \n")
- errors, ok := mig.UpSync(env.MustGet("DATABASE_URL"), env.Path("/migrations"))
- if !ok {
- for i, err := range errors {
- fmt.Printf("Error #%d: %s.\n", i, err)
- }
-
- panic("Migrations failed.")
- } else {
- fmt.Printf("Migrations finished with success.\n")
- }
-}
-
-func init() {
+func main() {
fmt.Printf("Application is starting...\n")
fmt.Printf("GO_ENV: %s\n", env.Current())
- migrate()
-}
-func main() {
db, err := dbx.New()
if err != nil {
panic(err)
}
+ db.Migrate()
ctx := &AppServices{
OAuth: &oauth.HTTPService{},