Skip to content

Commit

Permalink
Update sql.go to prepare db for test
Browse files Browse the repository at this point in the history
  • Loading branch information
cseteram committed Apr 10, 2022
1 parent becc2c7 commit 8a0b903
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strings"
"time"
"io/ioutil"

"github.com/bacchus-snu/reservation/config"
"github.com/bacchus-snu/reservation/types"
Expand Down Expand Up @@ -60,6 +61,32 @@ func TruncateForTest(tableName ...string) error {
return nil
}

func DropTableForTest(tableName ...string) error {
if !config.Config.IsTest {
panic("this function should be called only in test")
}
_, err := db.Exec(fmt.Sprintf("drop table %s", strings.Join(tableName, ",")))
if err != nil {
return err
}
return nil
}

func LoadScriptForTest(filePath string) error {
if !config.Config.IsTest {
panic("this function should be called only in test")
}
buf, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
_, err = db.Exec(string(buf))
if err != nil {
return err
}
return nil
}

type Tx struct {
tx *sql.Tx
}
Expand Down

0 comments on commit 8a0b903

Please sign in to comment.