Skip to content

Commit

Permalink
WIP tests for Podium lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Miranda committed Apr 10, 2018
1 parent 7b62b5d commit 2a3263a
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,78 @@ func InitializeTestServer(app *api.App) *httptest.Server {

var _ = Describe("Lib", func() {

var ts *httptest.Server
var a *api.App
var config *viper.Viper
var p *lib.Podium
var ts *httptest.Server
var config *viper.Viper

BeforeEach(func() {
BeforeSuite(func() {
a = GetDefaultTestApp()
ts = InitializeTestServer(a)
config = viper.New()
})

BeforeEach(func() {
//default configs for each test
config.Set("podium.url", ts.URL)
config.Set("leaderboards.globalLeaderboard", "ecg:leaderboard:global")
config.Set("leaderboards.localeLeaderboard", "ecg:leaderboard:%{locale}")
p = lib.NewPodium(config)
})

Describe("NewPodium", func() {
It("Should start a new instance of Podium Lib", func() {
p = lib.NewPodium(config)
Expect(p).NotTo(BeNil())
})
It("Should use podium.url from config files as the podium URL", func() {
config.Set("podium.url", "tempURL")
p = lib.NewPodium(config)
Expect(p.URL).To(Equal("tempURL"))
})
})

Describe("GetBaseLeaderboards", func() {
It("Should retrieve BaseLeaderboard from config files", func() {
config.Set("leaderboards.globalLeaderboard", "MyTestLeaderboard")
p = lib.NewPodium(config)
Expect(p.GetBaseLeaderboards()).To(Equal("MyTestLeaderboard"))
})
})

Describe("GetLocalizedLeaderboard", func() {
It("Should retrieve LocalizedLeaderboard from config files", func() {
config.Set("leaderboards.localeLeaderboard", "MyTestLeaderboard")
p = lib.NewPodium(config)
Expect(p.GetLocalizedLeaderboard("")).To(Equal("MyTestLeaderboard"))
})
It("Should change %{locale} in default localeLeaderboard value", func() {
config.Set("leaderboards.localeLeaderboard", "MyTestLeaderboard:%{locale}")
p = lib.NewPodium(config)
Expect(p.GetLocalizedLeaderboard("Brazil")).To(Equal("MyTestLeaderboard:Brazil"))
})
})

Describe("Healthcheck", func() {
It("Should respond with default WORKING string", func() {
status, body, _ := p.Healthcheck()
status, body, err := p.Healthcheck()
Expect(status).To(Equal(http.StatusOK))
Expect(body).To(Equal("WORKING"))
Expect(err).ToNot(HaveOccurred())
})
It("Should not respond with WORKING if server is down", func() {
config.Set("podium.url", "http://localhost:1")
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)
status, _, err := p.Healthcheck()

status, body, err := p.Healthcheck()
Expect(err).To(HaveOccurred())
Expect(status).NotTo(Equal(200))
Expect(body).NotTo(Equal("WORKING"))
})
})

AfterEach(func() {
AfterSuite(func() {
defer transport.CloseIdleConnections()
defer ts.Close()
})
Expand Down

0 comments on commit 2a3263a

Please sign in to comment.