This repository was archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rethinkdb -> postgresql integration test, fix connection leak in …
…pg client (#293)
- Loading branch information
1 parent
5ca7b95
commit 9460a03
Showing
9 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Source({name:"enron_source_rethink", namespace: 'enron.emails'}) | ||
.save({name:"enron_sink_postgres", namespace: 'enron.emails'}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// +build integration | ||
|
||
package integration_test | ||
|
||
import ( | ||
"database/sql" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/compose/transporter/log" | ||
|
||
_ "github.com/lib/pq" // import pq driver | ||
) | ||
|
||
const ( | ||
emailsSchema = `id varchar(24), | ||
body TEXT, | ||
filename varchar(255), | ||
headers jsonb, | ||
mailbox varchar(255), | ||
subFolder varchar(255), | ||
PRIMARY KEY (id)` | ||
) | ||
|
||
var ( | ||
postgresSourceSession *sql.DB | ||
cleanup = flag.Bool("cleanup", false, "used to determine whether or not to run cleanup function") | ||
) | ||
|
||
func setup() { | ||
log.Infoln("setting up tests") | ||
u := fmt.Sprintf("postgres://%s:%s@%s", | ||
os.Getenv("POSTGRES_ENRON_SINK_USER"), | ||
os.Getenv("POSTGRES_ENRON_SINK_PASSWORD"), | ||
os.Getenv("POSTGRES_ENRON_SINK_URI")) | ||
postgresSourceSession, _ = sql.Open("postgres", u) | ||
} | ||
|
||
func cleanupData() { | ||
log.Infoln("cleaning up data") | ||
|
||
if _, err := postgresSourceSession.Exec("DROP TABLE IF EXISTS emails;"); err != nil { | ||
log.Errorf("unable to drop table, could affect tests, %s", err) | ||
} | ||
|
||
_, err := postgresSourceSession.Exec(fmt.Sprintf("CREATE TABLE emails ( %s );", emailsSchema)) | ||
if err != nil { | ||
log.Errorf("unable to create table, could affect tests, %s", err) | ||
} | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
setup() | ||
if *cleanup { | ||
cleanupData() | ||
shutdown() | ||
os.Exit(0) | ||
return | ||
} | ||
code := m.Run() | ||
shutdown() | ||
os.Exit(code) | ||
} | ||
|
||
func shutdown() { | ||
log.Infoln("shutting down tests") | ||
log.Infoln("tests shutdown complete") | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// +build integration | ||
|
||
package integration_test | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRethinkToPostgresDocCount(t *testing.T) { | ||
var count int | ||
err := postgresSourceSession.QueryRow("SELECT COUNT(id) FROM emails;").Scan(&count) | ||
if err != nil { | ||
t.Errorf("unable to count table, %s", err) | ||
} | ||
if count != 5477 { | ||
t.Errorf("bad emailCount, expected 5477, got %d", count) | ||
} | ||
} |