dimanche 30 juillet 2017

Cannot make Goose DB Migration working for Go testing

I am currently learning Golang for web programming and now I continue by learning about database,Rest API and testing in Golang.

and now I got an issue with Goose database Migration and Go Testing integration.

I want to integrate goose migration to my Go testing code, my scenario is to up all migrations before test and then reset all database once testing is done.

my problem is I can't find any documentation/sample code to do it with Goose.

I also have tried to execute the goose command using exec.Command() but it always returns exit status 1

this is my existing code to trigger the migration up before testing being executed:

func pretest() {
      var args = []string{
          os.Getenv("DB_SERVER"),
          "\"user=" + os.Getenv("DB_USERNAME") + " dbname=" + os.Getenv("DB_TEST_NAME") + " sslmode=disable\"",
          "up",
      }   

      exe := exec.Command("goose", args...)
      exe.Dir = os.Getenv("DB_MIGRATION")
      /* result, err := exe.Output()*/
      //fmt.Println(string(result))
      /*fmt.Println(err)*/

      output := exe.Run()
      fmt.Println(output)
  }

enter image description here

my question is it possible to trigger migration (up/down/reset) from inside Go Code (in this case is testing code) ?

Why exec.Command() keep returning code status 1 but it work well when I execute another linux command (ls, pwd, mkdir are work well in the same way) ?

Aucun commentaire:

Enregistrer un commentaire