Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbindreiter committed Nov 18, 2024
1 parent cbf6e31 commit 3cb69c2
Show file tree
Hide file tree
Showing 24 changed files with 2,414 additions and 61 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches: [main]
pull_request:
merge_group:
branches: ["**"]

permissions:
contents: read # for golangci-lint-action

jobs:
tests:
name: Run tests
strategy:
matrix:
os: [Ubuntu]
go-version: ["1.23.x"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: |
go get ./...
go install github.com/jstemmer/go-junit-report@latest
- name: Build
run: go build -v ./...
- name: Run Tests
run: go test -v ./... | go-junit-report -set-exit-code > test-report.xml
- name: Test Summary
uses: test-summary/action@v2
with:
paths: "test-report.xml"
if: always()
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.62.0
39 changes: 39 additions & 0 deletions .github/workflows/protolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Lint

on:
push:
branches: [main]
pull_request:
merge_group:
branches: ["**"]

permissions: { }

jobs:
build:
name: Protolint
runs-on: ubuntu-latest

permissions:
contents: read
packages: read
# To report GitHub Actions status checks
statuses: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# super-linter needs the full git history to get the
# list of files that changed across commits
fetch-depth: 0

- name: Lint protocol buffers
uses: super-linter/super-linter@v6
env:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: .
PROTOBUF_CONFIG_FILE: .protolint.yaml
VALIDATE_PROTOBUF: true
92 changes: 92 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
# Inspired from: (MIT license) https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
---
run:
timeout: '5m'
linters-settings:
errcheck:
ignore: "" # https://github.com/golangci/golangci-lint/issues/4733
gosec:
excludes:
- G601 # Not relevant anymore with Go 1.22 and later
- G404 # Use of weak random number generator (math/rand instead of crypto/rand)
govet:
enable-all: true
disable:
- fieldalignment # too strict
- shadow # too strict
perfsprint:
strconcat: false
revive:
rules:
- name: var-naming
arguments:
- []
- []
- - skipPackageNameChecks: true
stylecheck:
checks: ["all", "-ST1003"]
linters:
enable:
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- canonicalheader # checks for canonical names in HTTP headers
- copyloopvar # detects places where loop variables are copied
#- contextcheck # checks for inherited context.Context
#- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # checks exhaustiveness of enum switch statements
- fatcontext # finds nested context.WithValue calls in loops
- forbidigo # forbids identifiers
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
#- gochecknoglobals # checks that no global variables exist
- gochecknoinits # checks that no init functions are present in Go code
- gochecksumtype # checks exhaustiveness on Go "sum types"
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
#- gomnd # detects magic numbers
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- intrange # finds places where for loops could make use of an integer range
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- mirror # reports wrong mirror patterns of bytes/strings usage
- musttag # enforces field tags in (un)marshaled structs
- nakedret # finds naked returns in functions greater than a specified function length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
- prealloc # finds slice declarations that could potentially be preallocated
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- protogetter # reports direct reads from proto message fields when getters should be used
- reassign # checks that package variables are not reassigned
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- rowserrcheck # checks whether Err of rows is checked successfully
- sloglint # ensure consistent code style when using log/slog
- spancheck # checks for mistakes with OpenTelemetry/Census spans
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- stylecheck # is a replacement for golint
- tagalign # checks that struct tags are well aligned
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- testableexamples # checks if examples are testable (have an expected output)
- testifylint # checks usage of github.com/stretchr/testify
#- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
- whitespace # detects leading and trailing whitespace
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

A Go SDK for interacting with [Loops's](https://loops.so) API.

## Installation

```bash
go get github.com/tilebox/loops-go
```

## Usage

Below are a few examples of how to use the SDK to send API requests.
Expand All @@ -22,7 +28,7 @@ import (

func main() {
ctx := context.Background()
client, err := loops.NewClient(loops.WithApiKey("YOUR_LOOPS_API_KEY"))
client, err := loops.NewClient(loops.WithAPIKey("YOUR_LOOPS_API_KEY"))
if err != nil {
slog.Error("failed to create client", slog.Any("error", err.Error()))
return
Expand All @@ -36,11 +42,9 @@ func main() {

**Find a contact**
```go
contactToFind := &loops.ContactIdentifier{
contact, err := client.FindContact(ctx, &loops.ContactIdentifier{
Email: loops.String("neil.armstrong@moon.space"),
}

contact, err := client.FindContact(ctx, contactToFind)
})
if err != nil {
slog.Error("failed to find contact", slog.Any("error", err.Error()))
return
Expand All @@ -49,15 +53,13 @@ if err != nil {

**Create a contact**
```go
newContact := &loops.Contact{
contactID, err := client.CreateContact(ctx, &loops.Contact{
Email: "neil.armstrong@moon.space",
FirstName: loops.String("Neil"),
LastName: loops.String("Armstrong"),
UserGroup: loops.String("Astronauts"),
Subscribed: true,
}

contactID, err := client.CreateContact(ctx, newContact)
})
if err != nil {
slog.Error("failed to create contact", slog.Any("error", err.Error()))
return
Expand All @@ -66,11 +68,9 @@ if err != nil {

**Delete a contact**
```go
contactToDelete := &loops.ContactIdentifier{
err = client.DeleteContact(ctx, &loops.ContactIdentifier{
Email: loops.String("neil.armstrong@moon.space"),
}

err = client.DeleteContact(ctx, contactToDelete)
})
if err != nil {
slog.Error("failed to delete contact", slog.Any("error", err.Error()))
return
Expand Down Expand Up @@ -112,12 +112,32 @@ if err != nil {
}
```

## Installation
## API Documentation

The API documentation is part of the official Loops Documentation and can be found [here](https://app.loops.so/docs/api-reference/).

## Contributing

Contributions are welcome! Especially if the loops API is updated, please feel free to open PRs for new or updated endpoints.

## Authors

Created by [Tilebox](https://tilebox.com) - The Solar System’s #1 developer tool for space data management.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Development

### Testing

```bash
go get github.com/tilebox/loops-go
go test ./...
```

## API Documentation
### Linting

The API documentation is part of the official Loops Documentation and can be found [here](https://app.loops.so/docs/api-reference/).
```bash
golangci-lint run --fix ./...
```
Loading

0 comments on commit 3cb69c2

Please sign in to comment.