Skip to content

Instantly share code, notes, and snippets.

@eftalyurtseven
Last active January 26, 2022 11:40
Show Gist options
  • Save eftalyurtseven/d74d5d3e10ef973df26dc037fd8f6cf7 to your computer and use it in GitHub Desktop.
Save eftalyurtseven/d74d5d3e10ef973df26dc037fd8f6cf7 to your computer and use it in GitHub Desktop.
package order
import (
"context"
"eftal/medium/mocks"
"errors"
"fmt"
"testing"
"github.com/golang/mock/gomock"
"github.com/jackc/pgx/v4"
)
func TestMakeAnOrder(t *testing.T) {
ctx := context.Background()
req := &orderRequest{
TableNumber: "B-1",
Products: map[string]int{
"Pizza": 5,
"Chefs' Special": 3,
"Coke": 2,
},
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
pool := mocks.NewMockFakePoolInterface(ctrl)
dummyError := fmt.Errorf("db.BeginTx failed with err: connection failed")
pool.EXPECT().BeginTx(ctx, pgx.TxOptions{}).Return(nil, dummyError)
ordersvc := &OrderService{db: pool}
_, err := ordersvc.Make(ctx, req)
if !errors.Is(err, dummyError) {
t.Fatalf("erros doesn't matched!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment