Skip to content
Permalink
Browse files
Adding interfaces for better operability and mock / testing (#17)
* Adding interfaces for better operability and mock / testing

* Update readme

* Add support for getters
  • Loading branch information
davidjumani committed Nov 7, 2021
1 parent 0f77353 commit ada7050cfebfeafa905caf5fd3c36d0e66b9f9ce
Showing 148 changed files with 47,318 additions and 292 deletions.
@@ -21,3 +21,4 @@ _testmain.go

*.exe
*.test
bin/mockgen
@@ -0,0 +1,31 @@
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

all: code mock-gen test

code:
go run generate/generate.go generate/layout.go --api=generate/listApis.json

FILES=$(shell for file in `pwd`/cloudstack/*Service.go ;do basename $$file .go ; done)
mock-gen:
@for f in $(FILES); do \
$(MOCKGEN) -destination=./cloudstack/$${f}_mock.go -package=cloudstack -copyright_file="header.txt" -source=./cloudstack/$${f}.go ; \
done

test:
go test -v ./...

MOCKGEN := $(shell pwd)/bin/mockgen
mockgen: ## Download conversion-gen locally if necessary.
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/mockgen)

@@ -57,15 +57,11 @@ Last but not the least, there are a lot of helper functions that will try to aut
## Developer Guide

The SDK relies on the `generate.go` script to auto generate the code for all the supported APIs listed in the `listApis.json` file.
The `listAPIs.json` file holds the output of `listApis` command for a specific release of CloudStack.
The `listAPIs.json` file holds the output of `listApis` command for a specific release of CloudStack.

```
# Build the generate.go script
cd generate/
go build
# Run the generator to auto-generate the code
./generate -api listApis.json
# Run it via the Makefile
make all
```

@@ -24,6 +24,11 @@ import (
"net/url"
)

type APIDiscoveryServiceIface interface {
ListApis(p *ListApisParams) (*ListApisResponse, error)
NewListApisParams() *ListApisParams
}

type ListApisParams struct {
p map[string]interface{}
}
@@ -46,6 +51,14 @@ func (p *ListApisParams) SetName(v string) {
p.p["name"] = v
}

func (p *ListApisParams) GetName() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["name"].(string)
return value, ok
}

// You should always use this function to get a new ListApisParams instance,
// as then you are sure you have configured all required params
func (s *APIDiscoveryService) NewListApisParams() *ListApisParams {

Some generated files are not rendered by default. Learn more.

0 comments on commit ada7050

Please sign in to comment.