mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Undo irrelevant changes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
bdfb2825a0
commit
5152f65972
4
go.mod
4
go.mod
@ -5,7 +5,7 @@ go 1.14
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/VividCortex/mysqlerr v0.0.0-20170204212430-6c6b55f8796f
|
||||
github.com/aws/aws-sdk-go v1.33.0
|
||||
github.com/aws/aws-sdk-go v1.29.20
|
||||
github.com/beevik/etree v1.1.0 // indirect
|
||||
github.com/benbjohnson/clock v0.0.0-20161215174838-7dc76406b6d3
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668
|
||||
@ -37,7 +37,7 @@ require (
|
||||
github.com/hashicorp/go-version v1.1.0
|
||||
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
|
||||
github.com/influxdata/influxdb-client-go v1.3.0
|
||||
github.com/jmespath/go-jmespath v0.3.0
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
|
||||
github.com/jung-kurt/gofpdf v1.10.1
|
||||
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
|
||||
github.com/klauspost/compress v1.4.1 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -17,8 +17,6 @@ github.com/apache/arrow/go/arrow v0.0.0-20200629181129-68b1273cbbf7/go.mod h1:QN
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/aws/aws-sdk-go v1.29.20 h1:vAHJhARpdbdeJstTVaugeHgvVj5lBnfz3blbbD24gfo=
|
||||
github.com/aws/aws-sdk-go v1.29.20/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
|
||||
github.com/aws/aws-sdk-go v1.33.0 h1:Bq5Y6VTLbfnJp1IV8EL/qUU5qO1DYHda/zis/sqevkY=
|
||||
github.com/aws/aws-sdk-go v1.33.0/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
|
||||
github.com/beevik/etree v1.0.1/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
||||
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
|
||||
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
||||
@ -182,8 +180,6 @@ github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZ
|
||||
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
|
||||
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
|
||||
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestMigrations(t *testing.T) {
|
||||
testDBs := []sqlutil.TestDB{
|
||||
sqlutil.Sqlite3TestDB(),
|
||||
sqlutil.TestDB_Sqlite3,
|
||||
}
|
||||
|
||||
for _, testDB := range testDBs {
|
||||
|
@ -1,12 +1,12 @@
|
||||
package migrator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/VividCortex/mysqlerr"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@ -115,22 +115,19 @@ func (db *Mysql) ColumnCheckSql(tableName, columnName string) (string, []interfa
|
||||
}
|
||||
|
||||
func (db *Mysql) CleanDB() error {
|
||||
tables, err := db.engine.DBMetas()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tables, _ := db.engine.DBMetas()
|
||||
sess := db.engine.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
for _, table := range tables {
|
||||
if _, err := sess.Exec("set foreign_key_checks = 0"); err != nil {
|
||||
return errutil.Wrap("failed to disable foreign key checks", err)
|
||||
return fmt.Errorf("failed to disable foreign key checks")
|
||||
}
|
||||
if _, err := sess.Exec("drop table " + table.Name + " ;"); err != nil {
|
||||
return errutil.Wrapf(err, "failed to delete table %q", table.Name)
|
||||
return fmt.Errorf("failed to delete table: %v, err: %v", table.Name, err)
|
||||
}
|
||||
if _, err := sess.Exec("set foreign_key_checks = 1"); err != nil {
|
||||
return errutil.Wrap("failed to disable foreign key checks", err)
|
||||
return fmt.Errorf("failed to disable foreign key checks")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,11 +130,11 @@ func (db *Postgres) CleanDB() error {
|
||||
defer sess.Close()
|
||||
|
||||
if _, err := sess.Exec("DROP SCHEMA public CASCADE;"); err != nil {
|
||||
return errutil.Wrap("failed to drop schema public", err)
|
||||
return fmt.Errorf("Failed to drop schema public")
|
||||
}
|
||||
|
||||
if _, err := sess.Exec("CREATE SCHEMA public;"); err != nil {
|
||||
return errutil.Wrap("failed to create schema public", err)
|
||||
return fmt.Errorf("Failed to create schema public")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -335,10 +335,9 @@ func (ss *SqlStore) readConfig() {
|
||||
type ITestDB interface {
|
||||
Helper()
|
||||
Fatalf(format string, args ...interface{})
|
||||
Logf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
// InitTestDB initializes the test DB.
|
||||
// InitTestDB initialize test DB.
|
||||
func InitTestDB(t ITestDB) *SqlStore {
|
||||
t.Helper()
|
||||
sqlstore := &SqlStore{}
|
||||
@ -350,7 +349,6 @@ func InitTestDB(t ITestDB) *SqlStore {
|
||||
|
||||
// environment variable present for test db?
|
||||
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
|
||||
t.Logf("Using database type %q", db)
|
||||
dbType = db
|
||||
}
|
||||
|
||||
@ -366,21 +364,20 @@ func InitTestDB(t ITestDB) *SqlStore {
|
||||
|
||||
switch dbType {
|
||||
case "mysql":
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.MySQLTestDB().ConnStr); err != nil {
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Mysql.ConnStr); err != nil {
|
||||
t.Fatalf("Failed to create key: %s", err)
|
||||
}
|
||||
case "postgres":
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.PostgresTestDB().ConnStr); err != nil {
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Postgres.ConnStr); err != nil {
|
||||
t.Fatalf("Failed to create key: %s", err)
|
||||
}
|
||||
default:
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.Sqlite3TestDB().ConnStr); err != nil {
|
||||
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Sqlite3.ConnStr); err != nil {
|
||||
t.Fatalf("Failed to create key: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// need to get engine to clean db before we init
|
||||
t.Logf("Creating database connection: %q", sec.Key("connection_string"))
|
||||
engine, err := xorm.NewEngine(dbType, sec.Key("connection_string").String())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to init test database: %v", err)
|
||||
@ -391,7 +388,6 @@ func InitTestDB(t ITestDB) *SqlStore {
|
||||
// temp global var until we get rid of global vars
|
||||
dialect = sqlstore.Dialect
|
||||
|
||||
t.Logf("Cleaning DB")
|
||||
if err := dialect.CleanDB(); err != nil {
|
||||
t.Fatalf("Failed to clean test db %v", err)
|
||||
}
|
||||
|
@ -1,65 +1,11 @@
|
||||
package sqlutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type TestDB struct {
|
||||
DriverName string
|
||||
ConnStr string
|
||||
}
|
||||
|
||||
func Sqlite3TestDB() TestDB {
|
||||
return TestDB{
|
||||
DriverName: "sqlite3",
|
||||
ConnStr: ":memory:",
|
||||
}
|
||||
}
|
||||
|
||||
func MySQLTestDB() TestDB {
|
||||
host := os.Getenv("MYSQL_HOST")
|
||||
if host == "" {
|
||||
host = "localhost"
|
||||
}
|
||||
port := os.Getenv("MYSQL_PORT")
|
||||
if port == "" {
|
||||
port = "3306"
|
||||
}
|
||||
return TestDB{
|
||||
DriverName: "mysql",
|
||||
ConnStr: fmt.Sprintf("grafana:password@tcp(%s:%s)/grafana_tests?collation=utf8mb4_unicode_ci", host, port),
|
||||
}
|
||||
}
|
||||
|
||||
func PostgresTestDB() TestDB {
|
||||
host := os.Getenv("POSTGRES_HOST")
|
||||
if host == "" {
|
||||
host = "localhost"
|
||||
}
|
||||
port := os.Getenv("POSTGRES_PORT")
|
||||
if port == "" {
|
||||
port = "5432"
|
||||
}
|
||||
connStr := fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanatest sslmode=disable",
|
||||
host, port)
|
||||
return TestDB{
|
||||
DriverName: "postgres",
|
||||
ConnStr: connStr,
|
||||
}
|
||||
}
|
||||
|
||||
func MSSQLTestDB() TestDB {
|
||||
host := os.Getenv("MSSQL_HOST")
|
||||
if host == "" {
|
||||
host = "localhost"
|
||||
}
|
||||
port := os.Getenv("MSSQL_PORT")
|
||||
if port == "" {
|
||||
port = "1433"
|
||||
}
|
||||
return TestDB{
|
||||
DriverName: "mssql",
|
||||
ConnStr: fmt.Sprintf("server=%s;port=%s;database=grafanatest;user id=grafana;password=Password!", host, port),
|
||||
}
|
||||
}
|
||||
var TestDB_Sqlite3 = TestDB{DriverName: "sqlite3", ConnStr: ":memory:"}
|
||||
var TestDB_Mysql = TestDB{DriverName: "mysql", ConnStr: "grafana:password@tcp(localhost:3306)/grafana_tests?collation=utf8mb4_unicode_ci"}
|
||||
var TestDB_Postgres = TestDB{DriverName: "postgres", ConnStr: "user=grafanatest password=grafanatest host=localhost port=5432 dbname=grafanatest sslmode=disable"}
|
||||
var TestDB_Mssql = TestDB{DriverName: "mssql", ConnStr: "server=localhost;port=1433;database=grafanatest;user id=grafana;password=Password!"}
|
||||
|
@ -1137,9 +1137,7 @@ func TestMSSQL(t *testing.T) {
|
||||
}
|
||||
|
||||
func InitMSSQLTestDB(t *testing.T) *xorm.Engine {
|
||||
testDB := sqlutil.MSSQLTestDB()
|
||||
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "localhost",
|
||||
serverIP, 1))
|
||||
x, err := xorm.NewEngine(sqlutil.TestDB_Mssql.DriverName, strings.Replace(sqlutil.TestDB_Mssql.ConnStr, "localhost", serverIP, 1))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to init mssql db %v", err)
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
// +build integration
|
||||
|
||||
package mysql
|
||||
|
||||
import (
|
||||
@ -1042,9 +1040,7 @@ func TestMySQL(t *testing.T) {
|
||||
}
|
||||
|
||||
func InitMySQLTestDB(t *testing.T) *xorm.Engine {
|
||||
testDB := sqlutil.MySQLTestDB()
|
||||
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "/grafana_tests",
|
||||
"/grafana_ds_tests", 1))
|
||||
x, err := xorm.NewEngine(sqlutil.TestDB_Mysql.DriverName, strings.Replace(sqlutil.TestDB_Mysql.ConnStr, "/grafana_tests", "/grafana_ds_tests", 1))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to init mysql db %v", err)
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
// +build integration
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
@ -974,11 +972,9 @@ func TestPostgres(t *testing.T) {
|
||||
}
|
||||
|
||||
func InitPostgresTestDB(t *testing.T) *xorm.Engine {
|
||||
testDB := sqlutil.PostgresTestDB()
|
||||
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "dbname=grafanatest",
|
||||
"dbname=grafanadstest", 1))
|
||||
x, err := xorm.NewEngine(sqlutil.TestDB_Postgres.DriverName, strings.Replace(sqlutil.TestDB_Postgres.ConnStr, "dbname=grafanatest", "dbname=grafanadstest", 1))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to init postgres DB %v", err)
|
||||
t.Fatalf("Failed to init postgres db %v", err)
|
||||
}
|
||||
|
||||
x.DatabaseTZ = time.UTC
|
||||
|
Loading…
Reference in New Issue
Block a user