Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Added more tests #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ on:
jobs:

build:
env:
# We overwrite this value to be 4 so
# the test can pass because if not the
# goroutines will not run in "parallel"
# and so the tests do not pass.
# 4 is because:
# * 1 Main run
# * 2 clients
# * 1 server
GOMAXPROCS: 4
IS_CI: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ build:
test: wasm ## Run the tests
@xvfb-run go test ./...

.PHONY: test
ctest: wasm ## Run the tests
@xvfb-run go test ./... -coverprofile=cover.out

.PHONY: test
cover: ## Run the cover tool
@cover -html=cover.out

.PHONY: dc-serve
dc-serve: ## Starts the server using docker-compose
@docker-compose -f docker/docker-compose.yml -f docker/develop.yml up --build --no-deps maze-wars
Expand Down
7 changes: 1 addition & 6 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
serverCmd = &cobra.Command{
Use: "server",
RunE: func(cmd *cobra.Command, args []string) error {
ss := &server.Store{}
d := flux.NewDispatcher()
out := os.Stdout
lvl := slog.LevelInfo
Expand All @@ -41,12 +40,8 @@ var (
l := slog.New(slog.NewTextHandler(out, &slog.HandlerOptions{
Level: lvl,
}))
ss := server.NewStore(d, l)
ad := server.NewActionDispatcher(d, l, ss)
rooms := server.NewRoomsStore(d, ss, l)
users := server.NewUsersStore(d, ss)

ss.Rooms = rooms
ss.Users = users

err := server.New(ad, ss, server.Options{
Port: viper.GetString("port"),
Expand Down
217 changes: 0 additions & 217 deletions integration/main_test.go

This file was deleted.

9 changes: 7 additions & 2 deletions server/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/xescugc/maze-wars/action"
"github.com/xescugc/maze-wars/store"
"github.com/xescugc/maze-wars/utils"
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
)

Expand Down Expand Up @@ -88,8 +89,12 @@ func (ac *ActionDispatcher) UserSignUp(un string) {
ac.Dispatch(action.NewUserSignUp(un))
}

func (ac *ActionDispatcher) UserSignIn(un string) {
ac.Dispatch(action.NewUserSignIn(un))
func (ac *ActionDispatcher) UserSignIn(un, ra string, ws *websocket.Conn) {
a := action.NewUserSignIn(un)
a.UserSignIn.RemoteAddr = ra
a.UserSignIn.Websocket = ws
a.UserSignIn.Username = un
ac.Dispatch(a)
}

func (ac *ActionDispatcher) UserSignOut(un string) {
Expand Down
Loading
Loading