Got MySQL connection working in Go

This commit is contained in:
Timothy Sehn
2020-09-14 16:26:57 -07:00
parent 3e17e271d2
commit 36f420276b
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package main
import "os"
import "fmt"
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
func main() {
var user = os.Args[1]
var port = os.Args[2]
var db = os.Args[3]
var dsn = user + "@tcp(127.0.0.1:" + port + ")/" + db
fmt.Println(dsn)
database, err := sql.Open("mysql", dsn)
if err != nil {
panic(err)
}
defer database.Close()
// Ping opens a connection
err = database.Ping()
if err != nil {
panic(err)
}
os.Exit(1)
}

View File

@@ -27,6 +27,10 @@ teardown() {
rm -rf $REPO_NAME
}
@test "go go-sql-drive/mysql test" {
go run $BATS_TEST_DIRNAME/go/go-sql-driver-mysql-test.go $USER $PORT $REPO_NAME
}
@test "python mysql.connector client" {
python3 $BATS_TEST_DIRNAME/python/mysql.connector-test.py $USER $PORT $REPO_NAME
}