https://github.com/api7/cloud-go-sdk
Go SDK for the API7 Cloud API
https://github.com/api7/cloud-go-sdk
golang mock sdk
Last synced: 5 months ago
JSON representation
Go SDK for the API7 Cloud API
- Host: GitHub
- URL: https://github.com/api7/cloud-go-sdk
- Owner: api7
- License: apache-2.0
- Created: 2022-09-13T05:54:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-26T08:25:53.000Z (almost 3 years ago)
- Last Synced: 2023-08-11T22:28:49.479Z (over 2 years ago)
- Topics: golang, mock, sdk
- Language: Go
- Homepage: https://pkg.go.dev/github.com/api7/cloud-go-sdk
- Size: 219 KB
- Stars: 1
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cloud-go-sdk
The Go SDK for accessing [API7 Cloud API](https://api7.cloud/api)
# Installation
Make sure you're using Go Modules to manage your Go Project, and your Go version needs to be `1.19` or later.
```shell
go mod init
```
Then, import the cloud-go-sdk in your Go program by running:
```go
import (
"github.com/api7/cloud-go-sdk"
)
```
Alternatively, download the cloud-go-sdk by running:
```shell
go get -u github.com/api7/cloud-go-sdk
```
# Mock
You may want to add unit test cases after you import cloud-go-sdk into your Go program,
for the sake of better integration, cloud-go-sdk uses [mockgen](https://github.com/golang/mock) to generate mock implementations.
e.g., for the `Interface`, we have a `MockInterface` implementation. If you want to mock an Application create error, you can write some codes like:
```go
ctrl := gomock.NewController(t) // var t *testing.T
cloud := NewMockInterface(ctrl)
cloud.EXPECT().CreateApplication(gomock.Any(), &Application{
ApplicationSpec: ApplicationSpec{
Name: "test app",
Description: "This is a test app",
Protocols: []string{ProtocolHTTP},
PathPrefix: "/api/v1",
Hosts: []string{"app.test.com"},
Upstreams: []UpstreamAndVersion{
{
Upstream: Upstream{
Scheme: "https",
LBType: "roundrobin",
Targets: []UpstreamTarget{
{
Host: "10.0.5.1",
Port: 80,
Weight: 100,
},
{
Host: "10.0.5.2",
Port: 80,
Weight: 100,
},
},
},
Version: "default",
},
},
DefaultUpstreamVersion: "default",
Active: ActiveStatus,
},
}, &ApplicationCreateOptions{
Cluster: &Cluster{
ID: 1,
},
}).Return(nil, errors.New("mock error"))
```
## Development
Run test cases via running:
```shell
make test
```
Regenerate mock codes by running:
```shell
make mockgen
```