Last active
February 10, 2021 07:58
-
-
Save percybolmer/9c59d4aeb330170e413dc72b88e277c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
"os" | |
"testing" | |
_ "github.com/lib/pq" | |
) | |
func TestThis(t *testing.T) { | |
} | |
func TestThis2(t *testing.T) { | |
} | |
// a Test that tries to connect to a PostgreSQL database | |
func TestConnect(t *testing.T) { | |
// First get some ENV variabeles | |
host := os.Getenv("POSTGRES_HOST") | |
user := os.Getenv("POSTGRES_USER") | |
port := os.Getenv("POSTGRES_PORT") | |
password := os.Getenv("POSTGRES_PASS") | |
dbname := os.Getenv("POSTGRES_DB") | |
psqlConnection := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname) | |
// open the DB connection | |
db, err := sql.Open("postgres", psqlConnection) | |
if err != nil { | |
t.Fatal(err) | |
} | |
// Make sure connection really works | |
err = db.Ping() | |
if err != nil { | |
t.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment