Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30d8418

Browse files
committed
Added more tests
1 parent b52665a commit 30d8418

File tree

16 files changed

+117
-28
lines changed

16 files changed

+117
-28
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,6 @@ Usage only `gin` package and oauth2 client/server mechanic
272272

273273
# Testing
274274
```
275-
export APP_WD=go_path to project_path/rsources or project_path/artifacts - needed for load templates
275+
export APP_WD=go_path to project_path/resources or project_path/artifacts - needed for load templates
276276
➜ make test
277277
```

‎app/auth/middleware.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/http"
66
"strings"
77

8-
"github.com/aristat/golang-example-app/common"
8+
"github.com/aristat/golang-example-app/app/common"
99

1010
"github.com/aristat/golang-example-app/app/logger"
1111

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎app/resolver/product.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88

99
"github.com/aristat/golang-example-app/app/db/domain"
1010

11+
"github.com/aristat/golang-example-app/app/common"
1112
"github.com/aristat/golang-example-app/app/grpc"
12-
"github.com/aristat/golang-example-app/common"
1313
"github.com/aristat/golang-example-app/generated/graphql"
1414
"github.com/aristat/golang-example-app/generated/resources/proto/products"
1515
"github.com/spf13/cast"

‎app/resolver/product_test.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"log"
77
"net"
88
"os"
9+
"strconv"
910
"testing"
1011

11-
"github.com/aristat/golang-example-app/common"
12+
"github.com/aristat/golang-example-app/app/common"
1213

1314
"github.com/aristat/golang-example-app/generated/resources/proto/products"
1415

@@ -23,16 +24,17 @@ import (
2324

2425
var (
2526
productServerHost = "localhost"
26-
productServerPort=":50051"
27+
grpcPortstring
2728
)
2829

2930
func TestMain(m *testing.M) {
30-
lis, err := net.Listen("tcp", productServerPort)
31+
lis, err := net.Listen("tcp", ":0")
3132
if err != nil {
3233
log.Fatalf(err.Error())
3334
}
3435
defer lis.Close()
3536

37+
grpcPort = ":" + strconv.Itoa(lis.Addr().(*net.TCPAddr).Port)
3638
s := grpc.NewServer()
3739
products.RegisterProductsServer(s, &resolver.ProductServerMock{})
3840

@@ -52,7 +54,7 @@ func TestList(t *testing.T) {
5254
ctx := context.Background()
5355
opts = append(opts, grpc.WithInsecure())
5456

55-
pool, _ := grpc1.NewPool(ctx, common.SrvProducts, productServerHost+productServerPort, grpc1.ConnOptions(opts...))
57+
pool, _ := grpc1.NewPool(ctx, common.SrvProducts, productServerHost+grpcPort, grpc1.ConnOptions(opts...))
5658
grpc1.SetPool(pool, common.SrvProducts)
5759

5860
cfg, _, err := resolver.BuildTest()

‎app/resolver/user.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package resolver
33
import (
44
"context"
55

6-
"github.com/aristat/golang-example-app/common"
6+
"github.com/aristat/golang-example-app/app/common"
77

88
graphql1 "github.com/aristat/golang-example-app/generated/graphql"
99
"github.com/spf13/cast"

‎app/routers/products-router/router.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/nats-io/stan.go"
1111

12-
"github.com/aristat/golang-example-app/common"
12+
"github.com/aristat/golang-example-app/app/common"
1313
"github.com/go-chi/chi"
1414
"github.com/nats-io/nats.go"
1515

@@ -32,13 +32,13 @@ func (router *Router) Run(chiRouter chi.Router) {
3232
chiRouter.Get("/products_slowly", router.GetProductsSlowly)
3333
}
3434

35-
func (service *Router) GetProductsGrpc(w http.ResponseWriter, r *http.Request) {
36-
conn, d, err := grpc.GetConnGRPC(service.poolManager, common.SrvProducts)
35+
func (router *Router) GetProductsGrpc(w http.ResponseWriter, r *http.Request) {
36+
conn, d, err := grpc.GetConnGRPC(router.poolManager, common.SrvProducts)
3737
defer d()
3838
defer r.Body.Close()
3939

4040
if err != nil {
41-
service.logger.Printf("[ERROR] %s", err.Error())
41+
router.logger.Printf("[ERROR] %s", err.Error())
4242
http.Error(w, err.Error(), http.StatusInternalServerError)
4343
return
4444
}
@@ -60,20 +60,20 @@ func (service *Router) GetProductsGrpc(w http.ResponseWriter, r *http.Request) {
6060
e.Encode(productOut)
6161
}
6262

63-
func (service *Router) GetProductsNats(w http.ResponseWriter, r *http.Request) {
63+
func (router *Router) GetProductsNats(w http.ResponseWriter, r *http.Request) {
6464
// Connect to NATS
65-
nc, err := nats.Connect(service.cfg.NatsURL)
65+
nc, err := nats.Connect(router.cfg.NatsURL)
6666
if err != nil {
67-
service.logger.Error(err.Error())
67+
router.logger.Error(err.Error())
6868
}
6969
defer nc.Close()
7070

7171
sc, err := stan.Connect("test-cluster", "stan-pub", stan.NatsConn(nc))
7272
message := "Hello"
73-
service.logger.Printf("[NATS] send %s", message)
74-
err = sc.Publish(service.cfg.Subject, []byte(message))
73+
router.logger.Printf("[NATS] send %s", message)
74+
err = sc.Publish(router.cfg.Subject, []byte(message))
7575
if err != nil {
76-
service.logger.Printf("[ERROR] %s", err.Error())
76+
router.logger.Printf("[ERROR] %s", err.Error())
7777
}
7878

7979
// Close connection
@@ -83,10 +83,10 @@ func (service *Router) GetProductsNats(w http.ResponseWriter, r *http.Request) {
8383
e.Encode("")
8484
}
8585

86-
func (service *Router) GetProductsSlowly(w http.ResponseWriter, r *http.Request) {
87-
service.logger.Info("Start sleep")
86+
func (router *Router) GetProductsSlowly(w http.ResponseWriter, r *http.Request) {
87+
router.logger.Info("Start sleep")
8888
time.Sleep(time.Second * 10)
89-
service.logger.Info("Stop sleep")
89+
router.logger.Info("Stop sleep")
9090
e := json.NewEncoder(w)
9191
e.Encode("")
9292
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /