This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* use http.server * responsechannel * less boilerplate * test-context * move tests in clients * rename * reorganize mocks
- Loading branch information
Elmer Bulthuis
committed
Aug 24, 2018
1 parent
db7c104
commit b47fa36
Showing
51 changed files
with
887 additions
and
947 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package clients | ||
|
||
import "testing" | ||
|
||
func TestGameyeClient_command(t *testing.T) { | ||
runInTestContext(t, func(ctx *testContext) (err error) { | ||
err = ctx.Client.command("noop", struct{}{}) | ||
if err != nil { | ||
return | ||
} | ||
return | ||
}) | ||
} |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package clients | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
/* | ||
testContext provides a handy context for testing | ||
*/ | ||
type testContext struct { | ||
Server *http.Server | ||
Client GameyeClient | ||
Response chan string | ||
} | ||
|
||
/* | ||
runInTestContext runs a test in a context | ||
*/ | ||
func runInTestContext(t *testing.T, job func(*testContext) error) { | ||
var err error | ||
defer func() { | ||
assert.NoError(t, err) | ||
}() | ||
|
||
responseChannel := make(chan string, 1) | ||
defer close(responseChannel) | ||
|
||
server := createAPITestServer(responseChannel) | ||
go server.ListenAndServe() | ||
defer server.Shutdown(context.Background()) | ||
|
||
client := NewGameyeClient(GameyeClientConfig{ | ||
Token: "", | ||
Endpoint: "http://localhost" + server.Addr + "", | ||
}) | ||
|
||
testContext := &testContext{ | ||
Client: client, | ||
Server: server, | ||
Response: responseChannel, | ||
} | ||
|
||
err = job(testContext) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package clients | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRunInContext(t *testing.T) { | ||
runInTestContext(t, func(ctx *testContext) (err error) { | ||
var res *http.Response | ||
res, err = http.Get("http://localhost" + ctx.Server.Addr + "/noop") | ||
if err != nil { | ||
return | ||
} | ||
assert.Equal(t, 204, res.StatusCode) | ||
return | ||
}) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package clients | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Gameye/gameye-sdk-go/models" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGameyeClient_SubscribeGame(t *testing.T) { | ||
runInTestContext(t, func(ctx *testContext) (err error) { | ||
var sub *GameQuerySubscription | ||
sub, err = ctx.Client.SubscribeGame() | ||
if err != nil { | ||
return | ||
} | ||
defer sub.Cancel() | ||
|
||
{ | ||
ctx.Response <- `[{"path":[],"value":{"game":{},"location":{}}}]` | ||
var state *models.GameQueryState | ||
state, err = sub.NextState() | ||
if err != nil { | ||
return | ||
} | ||
|
||
assert.NotNil(t, state) | ||
// assert.Equal(t, &GameStateMock, state) | ||
} | ||
|
||
return | ||
}) | ||
} | ||
|
||
func TestGameyeClient_QueryGame(t *testing.T) { | ||
runInTestContext(t, func(ctx *testContext) (err error) { | ||
ctx.Response <- `{"game":{},"location":{}}` | ||
|
||
var state *models.GameQueryState | ||
state, err = ctx.Client.QueryGame() | ||
if err != nil { | ||
return | ||
} | ||
|
||
assert.NotNil(t, state) | ||
// assert.Equal(t, &GameStateMock, state) | ||
|
||
return | ||
}) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.