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
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) |
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
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 |
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
FROM golang:latest | |
WORKDIR $GOPATH/src/todo | |
ENV GO111MODULE=on | |
COPY . . | |
RUN go build -o main . |
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
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 |
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
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. |
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
// 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 { |
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
type ListService struct { | |
repo ListRepository | |
} | |
func NewListService(repo ListRepository) (service ListService) { | |
return ListService{ | |
repo: repo, | |
} | |
} |
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
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) | |
} |
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
if(success){ | |
// do something | |
... | |
... | |
response.close() | |
value = false | |
} else { | |
... do things | |
response.close() |
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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"strings" | |
"sync" | |
) |
NewerOlder