Skip to content

Commit

Permalink
prepare for first version release (#3)
Browse files Browse the repository at this point in the history
* write utils_test unit test for CallWithRetries function

100% test coverage for api/utils package for now

* add github dev workflow

* add MIT LICENSE

* add readme
  • Loading branch information
98sean98 authored Jul 10, 2023
1 parent dbaccc0 commit 8e7ea59
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dev

on:
pull_request:

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"

- name: Vet
run: go vet ./...

- name: Test
run: go test -v -coverprofile=coverage.out ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
schema.gql
coverage.out
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Sean Chok <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SDK-GO

This is the Go SDK for Deploifai. It is used to interact with the Deploifai API.

## Installation

```shell
go get github.com/deploifai/sdk-go
```

## Usage

```go
package main

import (
"context"
"github.com/deploifai/sdk-go/config"
"github.com/deploifai/sdk-go/credentials"
"github.com/deploifai/sdk-go/service/workspace"
)

func main() {
// Create a new Credentials instance
creds := credentials.NewCredentials("<deploifai auth token>")

// Create a new config with the default config loader, and use the credentials
cfg, _ := config.LoadDefaultConfig(context.TODO(), config.WithCredentials(creds))

// Create a new workspace client
client := workspace.NewFromConfig(cfg)

// List all workspaces
_, _ = client.List(context.TODO())
}
```
48 changes: 48 additions & 0 deletions api/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package utils

import (
"fmt"
"testing"
)

// TestSuccessCallWithRetries tests the function CallWithRetries
// with a function that returns an error 2 times and then returns a result
func TestSuccessCallWithRetries(t *testing.T) {
counter := 0
f := func() (int32, error) {
if counter < 2 {
counter++
return 0, fmt.Errorf("error")
} else {
return 1, nil
}
}

result, err := CallWithRetries(f, nil, nil)
if err != nil {
t.Errorf("CallWithRetries returned an error after retrying")
}
if result != 1 {
t.Errorf("CallWithRetries returned a wrong result")
}
}

// TestErrorCallWithRetries tests the function CallWithRetries
// with a function that returns an error after 2 retries
func TestErrorCallWithRetries(t *testing.T) {
counter := 0
f := func() (int32, error) {
if counter < 2 {
counter++
return 0, fmt.Errorf("error")
} else {
return 1, nil
}
}

retryCount := 2
_, err := CallWithRetries(f, &retryCount, nil)
if err == nil {
t.Errorf("CallWithRetries did not return an error after retrying 3 times")
}
}

0 comments on commit 8e7ea59

Please sign in to comment.