-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
48 lines (43 loc) · 1.06 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gorilla/mux"
)
// NewTestServer helper for testing
func NewTestServer(path, method string, fn func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
hts := httptest.NewServer(func() *mux.Router {
rt := mux.NewRouter()
rt.HandleFunc(path, fn).Methods(method)
return rt
}())
return hts
}
func TestIntegration(t *testing.T) {
_, urt := Route()
ts := httptest.NewServer(urt)
defer ts.Close()
dbtest, err := InitializeDB()
fmt.Println(err)
datastore := Datastore{dbtest}
fmt.Println(err)
inv := &Inventory{
Name: "Cars",
Description: "Automobile",
Price: "4000",
Status: true,
}
resultInventory, err := datastore.CreateInventory(*inv)
assert.Nil(t, err)
_, err = datastore.GetInventory(resultInventory.Id)
assert.Nil(t, err)
list, err := datastore.ListInventory()
fmt.Println(list)
assert.NotNil(t, list)
assert.Nil(t, err)
err = datastore.DeleteInventory(resultInventory.Id)
assert.Nil(t, err)
}