Skip to content

Commit

Permalink
Change lib to be client (#70)
Browse files Browse the repository at this point in the history
* Change lib to be client
* Create `client` module

Co-authored-by: Arthur Nogueira Gonçalves <arthur.nogueira@wildlifestudios.com>
  • Loading branch information
arthur29 and Arthur Nogueira Gonçalves committed May 21, 2021
1 parent 0040e04 commit df197d6
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 58 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ build: ## Build the project
run: ## Execute the project
@go run main.go start

test: test-podium test-leaderboard ## Execute all tests
test: test-podium test-leaderboard test-client ## Execute all tests

test-podium: ## Execute all API tests
@ginkgo --cover -r -nodes=1 -skipPackage=leaderboard ./
@ginkgo --cover -r -nodes=1 -skipPackage=leaderboard,client ./

test-leaderboard: ## Execute all leaderboard tests
@cd leaderboard && ginkgo --cover -r -nodes=1 ./

test-client: ## Execute all client tests
@cd client && ginkgo --cover -r -nodes=1 ./

coverage: ## Generate code coverage file
@rm -rf _build
@mkdir -p _build
Expand Down
7 changes: 2 additions & 5 deletions lib/lib.go → client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package client

import (
"bytes"
Expand Down Expand Up @@ -89,10 +89,7 @@ type Response struct {
Reason string
}

func getHTTPClient(
timeout time.Duration,
maxIdleConns, maxIdleConnsPerHost int,
) *http.Client {
func getHTTPClient(timeout time.Duration, maxIdleConns, maxIdleConnsPerHost int) *http.Client {
once.Do(func() {
client = &http.Client{
Transport: getHTTPTransport(maxIdleConns, maxIdleConnsPerHost),
Expand Down
6 changes: 3 additions & 3 deletions lib/lib_suite_test.go → client/client_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib_test
package client_test

import (
. "github.com/onsi/ginkgo"
Expand All @@ -7,7 +7,7 @@ import (
"testing"
)

func TestLib(t *testing.T) {
func TestClient(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Lib Suite")
RunSpecs(t, "Client Suite")
}
22 changes: 11 additions & 11 deletions lib/lib_test.go → client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package lib_test
package client_test

import (
"github.com/spf13/viper"
"github.com/topfreegames/podium/lib"
"github.com/topfreegames/podium/client"
httpmock "gopkg.in/jarcoal/httpmock.v1"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Lib", func() {
var p lib.PodiumInterface
var _ = Describe("client", func() {
var p client.PodiumInterface
var config *viper.Viper
var globalLeaderboard string
var localeLeaderboard string
Expand All @@ -27,13 +27,13 @@ var _ = Describe("Lib", func() {
config.Set("podium.pass", "pass")
globalLeaderboard = "game:leaderboard:global"
localeLeaderboard = "game:leaderboard:us"
p = lib.NewPodium(config)
p = client.NewPodium(config)
httpmock.Reset()
})

Describe("NewPodium", func() {
It("Should start a new instance of Podium Lib", func() {
p = lib.NewPodium(config)
It("Should start a new instance of Podium Client", func() {
p = client.NewPodium(config)
Expect(p).NotTo(BeNil())
})
})
Expand Down Expand Up @@ -208,7 +208,7 @@ var _ = Describe("Lib", func() {
url := "http://podium/l/" + leaderboard + "/scores"
httpmock.RegisterResponder("PUT", url,
httpmock.NewStringResponder(200, `{ "success": true, "members": [ { "publicID": "1", "score": 2, "rank": 1, "previousRank": 1 } ] }`))
reqMembers := []*lib.Member{&lib.Member{Score: 1, PublicID: "1"}}
reqMembers := []*client.Member{&client.Member{Score: 1, PublicID: "1"}}
members, err := p.UpdateMembersScore(nil, leaderboard, reqMembers, 0)

Expect(members).NotTo(BeNil())
Expand All @@ -227,7 +227,7 @@ var _ = Describe("Lib", func() {
url := "http://podium/l/" + leaderboard + "/scores?prevRank=true&scoreTTL=10"
httpmock.RegisterResponder("PUT", url,
httpmock.NewStringResponder(200, `{ "success": true, "members": [ { "publicID": "1", "score": 2, "rank": 1, "previousRank": 1 } ] }`))
reqMembers := []*lib.Member{&lib.Member{Score: 1, PublicID: "1"}}
reqMembers := []*client.Member{&client.Member{Score: 1, PublicID: "1"}}
members, err := p.UpdateMembersScore(nil, leaderboard, reqMembers, 10)

Expect(members).NotTo(BeNil())
Expand Down Expand Up @@ -359,7 +359,7 @@ var _ = Describe("Lib", func() {

Expect(members).To(BeNil())
Expect(err).To(HaveOccurred())
reqErr, ok := err.(*lib.RequestError)
reqErr, ok := err.(*client.RequestError)
Expect(ok).To(BeTrue())
Expect(reqErr.Status()).To(BeNumerically("==", 404))
})
Expand Down Expand Up @@ -594,7 +594,7 @@ var _ = Describe("Lib", func() {
It("Should not respond if server is down", func() {
//set podium url to be wrong
config.Set("podium.url", "http://localhostel")
p = lib.NewPodium(config)
p = client.NewPodium(config)

body, err := p.Healthcheck(nil)

Expand Down
13 changes: 13 additions & 0 deletions client/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/topfreegames/podium/client

go 1.15

require (
github.com/golang/mock v1.5.0
github.com/onsi/ginkgo v1.16.2
github.com/onsi/gomega v1.12.0
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/spf13/viper v1.7.1
github.com/topfreegames/extensions v8.5.0+incompatible
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20190314184232-a8ac0a50d0b5
)
Loading

0 comments on commit df197d6

Please sign in to comment.