Skip to content

Instantly share code, notes, and snippets.

func TestE2E(t *testing.T) {
assert := assert.New(t)
client := &http.Client{}
req, err := http.NewRequest("GET", "localhost:8080/save?item=test122", nil)
assert.NoError(err, "error while initializing request")
res, err := client.Do(req)
assert.NoError(err, "error while making request")
assert.Equal(res.StatusCode, 200)
services:
mysql_db:
image: mysql:5.7
environment: # Set up mysql database name and password
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: todo
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- 3306:3306
FROM golang:latest
WORKDIR $GOPATH/src/todo
ENV GO111MODULE=on
COPY . .
RUN go build -o main .
func TestRepo(t *testing.T) {
assert := assert.New(t)
listRepo := todo.NewListRepository(Conn)
err := listRepo.Init()
assert.NoError(err, "error while initializing repo")
ID := uuid.New().String()
name := "itemName 1"
// Save Item
func TestMain(m *testing.M) {
// Create a new pool of connections
pool, err := dockertest.NewPool("myPool")
// Connect to docker on local machine
if err != nil {
log.Fatalf("Could not connect to docker: %s", err)
}
// Spawning a new MySQL docker container. We pass desired credentials for accessing it.
// ListRepository is an interface
type ListRepository interface {
SaveItem(ID string, name string) (err error)
FindItem(ID string) (res string, err error)
DeleteItem(ID string) (err error)
Init() (err error)
}
// MySQLListRepository impl of Listrepo
type MySQLListRepository struct {
type ListService struct {
repo ListRepository
}
func NewListService(repo ListRepository) (service ListService) {
return ListService{
repo: repo,
}
}
func main() {
// Initialize a connextion to DB. Sourcename contains the auth information, host information
// obtained from the env.
db, err := sql.Open("mysql", sourceName)
if err != nil {
panic(err)
}
Init(db)
}
if(success){
// do something
...
...
response.close()
value = false
} else {
... do things
response.close()
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"sync"
)