Skip to content

Commit

Permalink
chore: add tests + action
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jun 20, 2024
1 parent e5cd57b commit c572ab7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
args: --timeout 300s
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.21.3'
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run tests
run: go test -coverpkg=./... -coverprofile coverage.txt -v ./...
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: QuokkaStake/cosmos-validators-exporter
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ config*.toml
cosmos-validators-exporter
.idea/
dist/
cover.out
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ install:

lint:
golangci-lint run --fix ./...

test:
go test -coverpkg=./... -coverprofile cover.out -v ./...

coverage:
go tool cover -html=cover.out
40 changes: 40 additions & 0 deletions pkg/generators/balance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package generators

Check failure on line 1 in pkg/generators/balance_test.go

View workflow job for this annotation

GitHub Actions / lint

package should be `generators_test` instead of `generators` (testpackage)

import (
"main/pkg/constants"
"main/pkg/fetchers"
statePkg "main/pkg/state"
"main/pkg/types"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBalanceGeneratorNoState(t *testing.T) {
t.Parallel()

state := statePkg.NewState()
generator := NewBalanceGenerator()
results := generator.Generate(state)
assert.Empty(t, results)
}

func TestBlockSetValidators(t *testing.T) {
t.Parallel()

state := statePkg.NewState()
state.Set(constants.FetcherNameBalance, fetchers.BalanceData{
Balances: map[string]map[string][]types.Amount{
"chain": {
"validator": {
{Amount: 100, Denom: "uatom"},
{Amount: 200, Denom: "ustake"},
},
},
},
})

generator := NewBalanceGenerator()
results := generator.Generate(state)
assert.NotEmpty(t, results)
}

0 comments on commit c572ab7

Please sign in to comment.