Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rekram1-node committed Jan 3, 2023
1 parent dda5198 commit a12ef9a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 6 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pullRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint and Test before merging to main

on:
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19

- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build and Test
run: |
go get .
go build -v ./...
go test -v ./...
4 changes: 1 addition & 3 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ tasks:
test:
desc: "runs unit tests"
cmds:
- go test -v
sources:
- ./**/*.go
- go test -v ./...

build:
cmds:
Expand Down
35 changes: 35 additions & 0 deletions blink/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package blink_test

import (
"testing"

"github.com/rekram1-node/blinkgo/blink"
"github.com/stretchr/testify/assert"
)

func TestNewAccount(t *testing.T) {
tests := []struct {
name string
fakeEmail string
fakePass string
expectedAccount *blink.Account
}{
{
name: "NewAccount: Good Call",
fakeEmail: "example@example.com",
fakePass: "fakepassword",
expectedAccount: &blink.Account{
Email: "example@example.com",
Password: "fakepassword",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
account := blink.NewAccount(test.fakeEmail, test.fakePass)
assert.Equal(t, test.expectedAccount.Email, account.Email)
assert.Equal(t, test.expectedAccount.Password, account.Password)
assert.NotEqual(t, "", account.UniqueID)
})
}
}
1 change: 0 additions & 1 deletion blink/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (account *Account) updateAccountInfo(resp *LoginResponse) {
}

func (account *Account) RefreshToken() (*LoginResponse, error) {
// this method is incomplete
// this just for readability of code I created RefreshToken
return account.Login()
}
Expand Down
12 changes: 10 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ module github.com/rekram1-node/blinkgo

go 1.19

require github.com/go-resty/resty/v2 v2.7.0
require (
github.com/go-resty/resty/v2 v2.7.0
github.com/stretchr/testify v1.8.1
github.com/twinj/uuid v1.0.0
)

require (
github.com/twinj/uuid v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/myesui/uuid v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
gopkg.in/stretchr/testify.v1 v1.2.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/myesui/uuid v1.0.0 h1:xCBmH4l5KuvLYc5L7AS7SZg9/jKdIFubM7OVoLqaQUI=
github.com/myesui/uuid v1.0.0/go.mod h1:2CDfNgU0LR8mIdO8vdWd8i9gWWxLlcoIGGpSNgafq84=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/twinj/uuid v1.0.0 h1:fzz7COZnDrXGTAOHGuUGYd6sG+JMq+AoE7+Jlu0przk=
github.com/twinj/uuid v1.0.0/go.mod h1:mMgcE1RHFUFqe5AfiwlINXisXfDGro23fWdPUfOMjRY=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
Expand All @@ -9,3 +23,10 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/stretchr/testify.v1 v1.2.2 h1:yhQC6Uy5CqibAIlk1wlusa/MJ3iAN49/BsR/dCCKz3M=
gopkg.in/stretchr/testify.v1 v1.2.2/go.mod h1:QI5V/q6UbPmuhtm10CaFZxED9NreB8PnFYN9JcR6TxU=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47 changes: 47 additions & 0 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package client_test

import (
"testing"

"github.com/go-resty/resty/v2"
"github.com/rekram1-node/blinkgo/internal/client"
"github.com/stretchr/testify/assert"
)

func TestDefault(t *testing.T) {
tests := []struct {
name string
}{
{
name: "Default: Good Call",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var c *resty.Client
defaultClient := client.Default()
assert.NotNil(t, defaultClient)
assert.IsType(t, c, defaultClient)
})
}
}

func TestNew(t *testing.T) {
tests := []struct {
name string
mockAuthToken string
}{
{
name: "New: Good Call",
mockAuthToken: "fake-token",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var c *resty.Client
newClient := client.New(test.mockAuthToken)
assert.NotNil(t, newClient)
assert.IsType(t, c, newClient)
})
}
}

0 comments on commit a12ef9a

Please sign in to comment.