diff --git a/database/README.md b/database/README.md index 2ea24d8..04b5cdf 100644 --- a/database/README.md +++ b/database/README.md @@ -39,6 +39,6 @@ Follow-up Questions: ## Exercise 3 mock database -Using your new database interface mock the database functions into your [tests from last week.](../restful-go/ex-4-tests/framework_test.go) +Using your new database interface mock the database functions into your [tests from last week.](../restful-go/ex-4-tests/framework_test.go). The goal is to imitate db interactions without connecting to the db. You will need to add the DB package to the same repo that your server lives in. -TODO: copy tests from cli-game. and edit the interface to be inside the test suite. +[Here](https://github.com/Soypete/golang-cli-game/blob/24dc57852dee27bb17120555d3d390bd17a78d13/server/api_test.go#L14) are some working tests that use `passBD{}` and `failDB{}` to mock database functionality in an api test. diff --git a/database/ex-3-custom-tooling/main.go b/database/ex-3-custom-tooling/main.go deleted file mode 100644 index e652161..0000000 --- a/database/ex-3-custom-tooling/main.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "fmt" - "net/url" - - "github.com/jmoiron/sqlx" -) - -type connection interface { - GetUserData(string) (string, error) - UpsertUsername(string) error - DeleteUsername(string) error - CreateGame(string) (int64, error) - AddUserToGame(string, int64) error - GetGameData(int64) (string, error) - StopGame(int64) error -} - -type client struct { - db *sqlx.DB -} - -func setup() *client { - // connect to db - params := url.Values{} - params.Set("sslmode", "disable") - - connectionString := url.URL{ - Scheme: "postgresql", - User: url.UserPassword("postgres", "postgres"), - Host: "localhost:5431", - Path: "postgres", - RawQuery: params.Encode(), - } - db, err := sqlx.Connect("postgres", connectionString.String()) - if err != nil { - panic(err) - } - - return &client{ - db: db, - } -} -func main() { - dbClient := setup() - - fmt.Println(dbClient.db.Ping()) - -}