-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare for first version release (#3)
* 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
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
schema.gql | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |