github.com/kotovmak/go-admin@v1.1.1/modules/db/statement_postgresql_test.go (about)

     1  package db
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/exec"
     7  	"path"
     8  	"testing"
     9  
    10  	_ "github.com/kotovmak/go-admin/modules/db/drivers/postgres"
    11  )
    12  
    13  var driverTestPgConn Connection
    14  
    15  func InitPostgresql() {
    16  
    17  	cmd := exec.Command("createdb -p 5433 -U postgres " + driverTestDBName)
    18  	cmd.Env = os.Environ()
    19  	cmd.Env = append(cmd.Env, "PGPASSWORD=root")
    20  	_ = cmd.Run()
    21  
    22  	cmd = exec.Command("psql", "-h", "localhost", "-U", "root", "-proot", "-d", driverTestDBName,
    23  		"-f", path.Dir(path.Dir(testCurrentPath()))+"/data/admin.pgsql")
    24  	cmd.Env = os.Environ()
    25  	cmd.Env = append(cmd.Env, "PGPASSWORD=root")
    26  	err := cmd.Run()
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  
    31  	driverTestPgConn = testConnDSN(DriverPostgresql, fmt.Sprintf("host=127.0.0.1 port=5433 user=postgres "+
    32  		"password=root dbname=%s sslmode=disable", driverTestDBName))
    33  }
    34  
    35  func TestPgSQL_WhereIn(t *testing.T)         { testSQLWhereIn(t, driverTestPgConn) }
    36  func TestPgSQL_Count(t *testing.T)           { testSQLCount(t, driverTestPgConn) }
    37  func TestPgSQL_Select(t *testing.T)          { testSQLSelect(t, driverTestPgConn) }
    38  func TestPgSQL_OrderBy(t *testing.T)         { testSQLOrderBy(t, driverTestPgConn) }
    39  func TestPgSQL_GroupBy(t *testing.T)         { testSQLGroupBy(t, driverTestPgConn) }
    40  func TestPgSQL_Skip(t *testing.T)            { testSQLSkip(t, driverTestPgConn) }
    41  func TestPgSQL_Take(t *testing.T)            { testSQLTake(t, driverTestPgConn) }
    42  func TestPgSQL_Where(t *testing.T)           { testSQLWhere(t, driverTestPgConn) }
    43  func TestPgSQL_WhereNotIn(t *testing.T)      { testSQLWhereNotIn(t, driverTestPgConn) }
    44  func TestPgSQL_Find(t *testing.T)            { testSQLFind(t, driverTestPgConn) }
    45  func TestPgSQL_Sum(t *testing.T)             { testSQLSum(t, driverTestPgConn) }
    46  func TestPgSQL_Max(t *testing.T)             { testSQLMax(t, driverTestPgConn) }
    47  func TestPgSQL_Min(t *testing.T)             { testSQLMin(t, driverTestPgConn) }
    48  func TestPgSQL_Avg(t *testing.T)             { testSQLAvg(t, driverTestPgConn) }
    49  func TestPgSQL_WhereRaw(t *testing.T)        { testSQLWhereRaw(t, driverTestPgConn) }
    50  func TestPgSQL_UpdateRaw(t *testing.T)       { testSQLUpdateRaw(t, driverTestPgConn) }
    51  func TestPgSQL_LeftJoin(t *testing.T)        { testSQLLeftJoin(t, driverTestPgConn) }
    52  func TestPgSQL_WithTransaction(t *testing.T) { testSQLWithTransaction(t, driverTestPgConn) }
    53  func TestPgSQL_WithTransactionByLevel(t *testing.T) {
    54  	testSQLWithTransactionByLevel(t, driverTestPgConn)
    55  }
    56  func TestPgSQL_First(t *testing.T)       { testSQLFirst(t, driverTestPgConn) }
    57  func TestPgSQL_All(t *testing.T)         { testSQLAll(t, driverTestPgConn) }
    58  func TestPgSQL_ShowColumns(t *testing.T) { testSQLShowColumns(t, driverTestPgConn) }
    59  func TestPgSQL_ShowTables(t *testing.T)  { testSQLShowTables(t, driverTestPgConn) }
    60  func TestPgSQL_Update(t *testing.T)      { testSQLUpdate(t, driverTestPgConn) }
    61  func TestPgSQL_Delete(t *testing.T)      { testSQLDelete(t, driverTestPgConn) }
    62  func TestPgSQL_Exec(t *testing.T)        { testSQLExec(t, driverTestPgConn) }
    63  func TestPgSQL_Insert(t *testing.T)      { testSQLInsert(t, driverTestPgConn) }
    64  func TestPgSQL_Wrap(t *testing.T)        { testSQLWrap(t, driverTestPgConn) }