Пример #1
0
// NAME
//   check data generated from ModSQL into a Postgre database
//
// DESCRIPTION
//
//   To create the database:
//
//     sudo -u postgres createuser USER --no-superuser --no-createrole --no-createdb
//     sudo -u postgres createdb modsql_test --owner USER
//
//   Note: substitute "USER" by your user name.
//
//   To remove it:
//
//     sudo -u postgres dropdb modsql_test
func TaskTestPostgres(t *tasking.T) {
	db, err := sql.Open("postgres", fmt.Sprintf("user=%s dbname=%s host=%s sslmode=disable",
		username, dbname, host.postgres))
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.Postgres)

		if err = modsql.Load(db, filepath.Join("data", "sql", "postgres_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}
Пример #2
0
// NAME
//   test-mysql - check data generated from ModSQL into a MySQL database
//
// DESCRIPTION
//
//   To create the database:
//
//     mysql -p
//     mysql> create database modsql_test;
//     mysql> GRANT ALL PRIVILEGES ON modsql_test.* to USER@localhost;
//
//   Note: substitute "USER" by your user name.
//
//   To remove it:
//
//     mysql> drop database modsql_test;
func TaskTestMySQL(t *tasking.T) {
	// Format used in "github.com/serbaut/go-mysql"
	//db, err := sql.Open("mysql", fmt.Sprintf("mysql://%s@(unix)/%s?socket=%s",
	//username, dbname, host.mysql))
	db, err := sql.Open("mysql", fmt.Sprintf("%s@unix(%s)/%s?parseTime=true",
		username, host.mysql, dbname))
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.MySQL)

		if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}
Пример #3
0
// NAME
//   test-sqlite - check data generated from ModSQL into a SQLite database
func TaskTestSQLite(t *tasking.T) {
	filename := dbname + ".db"
	defer func() {
		if err := os.Remove(filename); err != nil {
			t.Error(err)
		}
	}()

	db, err := sql.Open("sqlite3", filename)
	if err != nil {
		t.Fatal(err)
	}

	if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_init.sql")); err != nil {
		t.Error(err)
	} else {
		if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_test.sql")); err != nil {
			t.Error(err)
		}

		testInsert(t, db, modsql.SQLite)

		if err = modsql.Load(db, filepath.Join("data", "sql", "sqlite_drop.sql")); err != nil {
			t.Error(err)
		}
	}

	db.Close()

	if !t.Failed() {
		t.Log("--- PASS")
	}
}