Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test and coverage report #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Go Test Automation with Coverage

on:
pull_request:
branches:
- main

jobs:
test:
name: Run Go Tests and Coverage
runs-on: ubuntu-latest # Use GitHub-hosted Ubuntu runner

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23 # Adjust to your required Go version

- name: Install dependencies
run: go mod tidy

- name: Run tests with coverage
run: go test -coverprofile=coverage.out -covermode=atomic ./...

- name: Generate coverage report
run: go tool cover -func=coverage.out

- name: Upload coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
228 changes: 228 additions & 0 deletions caches.go

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

34 changes: 34 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
"encoding/json"
"errors"
"fmt"
"iter"
"net/url"
"reflect"
"strconv"
)

// Ptr returns a pointer to its argument.
Expand Down Expand Up @@ -128,3 +131,34 @@ func deepMarshal(input any, output *map[string]any) error {
}
return nil
}

func createURLQuery(query map[string]any) (string, error) {
v := url.Values{}
for key, value := range query {
switch value := value.(type) {
case string:
v.Add(key, value)
case int:
v.Add(key, strconv.Itoa(value))
case float64:
v.Add(key, strconv.FormatFloat(value, 'f', -1, 64))
case bool:
v.Add(key, strconv.FormatBool(value))
case []any:
for _, item := range value {
v.Add(key, item.(string))
}
default:
return "", fmt.Errorf("unsupported type: %T", value)
}
}
return v.Encode(), nil
}

func yieldErrorAndEndIterator[T any](err error) iter.Seq2[*T, error] {
return func(yield func(*T, error) bool) {
if !yield(nil, err) {
return
}
}
}
Loading
Loading