This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7263536
commit b7eb929
Showing
8 changed files
with
74 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package spin_test | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"github.com/tchaudhry91/spinme/spin" | ||
"strings" | ||
"time" | ||
|
||
_ "github.com/lib/pq" | ||
) | ||
|
||
func ExamplePostgres() { | ||
out, err := spin.Postgres(context.Background(), nil) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer spin.SlashID(context.Background(), out.ID) | ||
// Give postgres a couple of seconds to boot-up, sadly there is no "ready" check yet | ||
time.Sleep(2 * time.Second) | ||
var hostEp string | ||
var ok bool | ||
// Grab the host endpoint mapping for the container | ||
if hostEp, ok = out.Endpoints["5432/tcp"]; !ok { | ||
fmt.Println("Didn't find expected port mapping") | ||
} | ||
// pq nees an independent port, not the entire endpoint | ||
ep := strings.Split(hostEp, ":") | ||
connStr := fmt.Sprintf("user=postgres password=password dbname=testdb port=%s sslmode=disable", ep[len(ep)-1]) | ||
db, err := sql.Open("postgres", connStr) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println("Connected!") | ||
//Output: Connected! | ||
} |
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