Skip to content

Commit

Permalink
Refactor CodeBase To Cater For Airtime Module
Browse files Browse the repository at this point in the history
Move airtime related operations to a specified module
Update Circle CI test command to cater for tests in subfolders
Fix imports broken due to refactoring
  • Loading branch information
Ghvstcode committed May 11, 2021
1 parent adc355a commit e6b6144
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- "/go/pkg/mod"
- run:
name: Run tests
command: go test -race -coverprofile=coverage.txt -covermode=atomic
command: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
- run:
name: Upload Coverage
when: on_success
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Reloadly SDK for Golang

[![CircleCI][circle-ci-badge]][circle-ci-url] [![MIT][mit-badge]][mit-url] [![codecov][codecov-badge]][codecov-url]
<!--[![Maven][maven-badge]][maven-url]-->

The **Reloadly SDK for Golang** enables Go developers to easily work with [Reloadly Services][reloadly-main-site] and build scalable solutions. You can get started in minutes if you have Go 1.15+ installed on your machine.

* [SDK Homepage][sdk-website] (Coming soon)
Expand Down Expand Up @@ -118,9 +116,9 @@ This project is licensed under the MIT license. See the [LICENSE](LICENSE) file

[circle-ci-url]: https://app.circleci.com/pipelines/github/Reloadly/reloadly-sdk-golang

[codecov-badge]: https://codecov.io/gh/reloadly/reloadly-sdk-java/branch/main/graph/badge.svg?token=8U89VKQ2BF
[codecov-badge]: https://codecov.io/gh/Reloadly/reloadly-sdk-golang/branch/main/graph/badge.svg?token=SUV66Q3J2Y

[codecov-url]: https://app.codecov.io/gh/reloadly/reloadly-sdk-java
[codecov-url]: https://codecov.io/gh/Reloadly/reloadly-sdk-golang

[youtube-series]: https://www.youtube.com/watch?v=TbXC4Ic8x30&t=141s&ab_channel=Reloadly

Expand Down
2 changes: 1 addition & 1 deletion accounts.go → airtime/accounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions accounts_test.go → airtime/accounts_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package reloadly_test
package airtime_test

import (
"encoding/json"
"github.com/reloadly/reloadly-sdk-golang"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
"net/http"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion countries.go → airtime/countries.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
26 changes: 26 additions & 0 deletions airtime/countries_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package airtime_test

import (
"net/http"
"testing"
)

func TestClient_GetCountries(t *testing.T) {
teardown := setup()

defer teardown()

mux.HandleFunc("/countries", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
})

body, err := client.GetCountries()

if err == nil {
t.Errorf("Expected error to be %q but got nil", err)
}

if body != nil {
t.Errorf("Expected body to be nil but got %q", body)
}
}
2 changes: 1 addition & 1 deletion discounts.go → airtime/discounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
37 changes: 37 additions & 0 deletions airtime/discounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package airtime_test

import (
"encoding/json"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
"net/http"
"testing"
)

func TestClient_GetDiscounts(t *testing.T) {
teardown := setup()

defer teardown()

mux.HandleFunc("/operators/commissions", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
data := reloadly.Discounts{
TotalElements: 20,
TotalPages: 5,
}
json.NewEncoder(rw).Encode(data)

})

body, err := client.GetDiscounts()
if err != nil {
t.Errorf("Expected error to be nil but got %q", err)
}

if body.TotalPages != 5 {
t.Errorf("Expected TotalPages to be 5 but got %v", body.TotalPages)
}

if body.TotalElements != 20 {
t.Errorf("Expected TotalElements to be 20 but got %v", body.TotalElements)
}
}
2 changes: 1 addition & 1 deletion operators.go → airtime/operators.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"bytes"
Expand Down
30 changes: 28 additions & 2 deletions operators_test.go → airtime/operators_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package reloadly_test
package airtime_test

import (
"encoding/json"
"github.com/reloadly/reloadly-sdk-golang"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
"net/http"
"testing"
)
Expand Down Expand Up @@ -55,4 +55,30 @@ func TestClient_GetFXRate(t *testing.T) {
if body.FxRate != 65 {
t.Errorf("Expected OperatorID to be 65 but got %v", body.FxRate)
}
}

func TestClient_GetOperatorsByISO(t *testing.T) {
teardown := setup()

defer teardown()

mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
data := reloadly.Operators{
TotalPages: 5,
Size: 20,
}

json.NewEncoder(rw).Encode(data)

})

body, err := client.GetOperatorsByISO("011")
if err != nil {
t.Errorf("Expected error to be nil but got %q", err)
}

if body.Size != 20 {
t.Errorf("Expected Size to be 20 but got %v", body.Size)
}
}
2 changes: 1 addition & 1 deletion promotions.go → airtime/promotions.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions promotions_test.go → airtime/promotions_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package reloadly_test
package airtime_test

import (
"encoding/json"
"github.com/reloadly/reloadly-sdk-golang"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
"net/http"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion reloadly.go → airtime/reloadly.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/base64"
Expand Down
2 changes: 1 addition & 1 deletion reports.go → airtime/reports.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions reports_test.go → airtime/reports_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package reloadly_test
package airtime_test

import (
"encoding/json"
"github.com/reloadly/reloadly-sdk-golang"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
"net/http"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion topup.go → airtime/topup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reloadly
package airtime

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions topup_test.go → airtime/topup_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package reloadly_test
package airtime_test

import (
"encoding/json"
"github.com/reloadly/reloadly-sdk-golang"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
Err "github.com/reloadly/reloadly-sdk-golang/error"
"net/http"
"net/http/httptest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package main

import (
"fmt"
"github.com/Reloadly/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package main

import (
"fmt"
"github.com/Reloadly/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ currency**.

import (
"fmt"
"github.com/Ghvstcode/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on the different operators promotions and to showcase these to your customers.

import (
"fmt"
"github.com/Ghvstcode/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Retrieve various reports such as transaction history etc...

import (
"fmt"
"github.com/Ghvstcode/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package main

import (
"fmt"
"github.com/Ghvstcode/reloadly"
reloadly "github.com/reloadly/reloadly-sdk-golang/airtime"
)

func main (){
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion authentication/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNewAuthClient(t *testing.T) {
if res != nil{
t.Skip("Skipped the rest of the tests")
if c.ExpectedSandbox != res.SandBox{
t.Fatalf("Expected Sandbox to be %s but got %s", c.ExpectedSandbox, res.URL)
t.Fatalf("Expected Sandbox to be %t but got %s", c.ExpectedSandbox, res.URL)
}

}
Expand Down

0 comments on commit e6b6144

Please sign in to comment.