Skip to content

Commit

Permalink
feat: support List and All method on Caches struct
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 727042892
  • Loading branch information
happy-qiao authored and copybara-github committed Feb 14, 2025
1 parent 01b042e commit 0f98a76
Show file tree
Hide file tree
Showing 7 changed files with 491 additions and 17 deletions.
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

0 comments on commit 0f98a76

Please sign in to comment.