Skip to content

Commit

Permalink
Code coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
NiJeTi committed Jan 3, 2025
1 parent c90caa7 commit a75c20b
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ github.token }}

- name: 'Extract meta'
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ github.token }}

- name: 'Extract meta'
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
port: ${{ secrets.PORT }}
script: |
docker login \
-u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} \
-u ${{ github.actor }} -p ${{ github.token }} \
ghcr.io
- name: 'Copy docker-compose.yaml'
Expand Down
66 changes: 54 additions & 12 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,78 @@ on:
- 'internal/**'

env:
GO_VERSION: '1.23'
LINTER_VERSION: 'v1.62.2'

MIGRATOR: './cmd/migrator/'
SERVICE: 'cmd/service/main.go'

COVERAGE_FILE: 'coverage.out'

jobs:
validate:
build:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Setup Go'
uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: ${{ env.GO_VERSION }}

- name: 'Install dependencies'
run: go mod download
- name: 'Build migrator'
run: go build ${{ env.MIGRATOR }}

- name: 'Build service'
run: go build ${{ env.SERVICE }}

lint:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Run linters'
uses: golangci/golangci-lint-action@v6
with:
version: v1.62.2
args: --timeout=2m
version: ${{ env.LINTER_VERSION }}
args: --timeout=2m

- name: 'Build migrator'
run: go build ${{ env.MIGRATOR }}

- name: 'Build service'
run: go build ${{ env.SERVICE }}
test:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Setup Go'
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: 'Test'
run: go test -v ./...
run: |
go test \
-cover \
-covermode=atomic \
-coverprofile=${{ env.COVERAGE_FILE }} \
./...
- name: 'Upload coverage result'
uses: coverallsapp/github-action@v2
with:
github-token: ${{ github.token }}
file: ${{ env.COVERAGE_FILE }}
format: golang
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lint:

.PHONY: test
test:
go test -coverprofile=coverage.out ./...
go test -cover -covermode=atomic -coverprofile=coverage.out ./...

.PHONY: debug
debug:
Expand Down
80 changes: 80 additions & 0 deletions internal/generated/mocks/pkg/discordUtils/interaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion internal/pkg/discordUtils/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"github.com/bwmarrin/discordgo"
)

type interaction interface {
ApplicationCommandData() discordgo.ApplicationCommandInteractionData
}

func OptionsMap(
i *discordgo.Interaction,
i interaction,
) map[string]*discordgo.ApplicationCommandInteractionDataOption {
options := i.ApplicationCommandData().Options

Expand Down
42 changes: 42 additions & 0 deletions internal/pkg/discordUtils/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package discordUtils_test

import (
"testing"

"github.com/bwmarrin/discordgo"
"github.com/stretchr/testify/assert"

mocks "github.com/nijeti/cinema-keeper/internal/generated/mocks/pkg/discordUtils"
"github.com/nijeti/cinema-keeper/internal/pkg/discordUtils"
)

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

i := mocks.NewMockInteraction(t)

wantOptions := map[string]*discordgo.ApplicationCommandInteractionDataOption{
"string": {
Name: "string",
Type: discordgo.ApplicationCommandOptionString,
},
"int": {
Name: "int",
Type: discordgo.ApplicationCommandOptionInteger,
},
"bool": {
Name: "bool",
Type: discordgo.ApplicationCommandOptionBoolean,
},
}

data := discordgo.ApplicationCommandInteractionData{}
for _, opt := range wantOptions {
data.Options = append(data.Options, opt)
}
i.EXPECT().ApplicationCommandData().Return(data)

options := discordUtils.OptionsMap(i)

assert.Equal(t, wantOptions, options)
}

0 comments on commit a75c20b

Please sign in to comment.