Skip to content

Commit ada7050

Browse files
authored
Adding interfaces for better operability and mock / testing (#17)
* Adding interfaces for better operability and mock / testing * Update readme * Add support for getters
1 parent 0f77353 commit ada7050

148 files changed

Lines changed: 47318 additions & 292 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ _testmain.go
2121

2222
*.exe
2323
*.test
24+
bin/mockgen

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2+
ifeq (,$(shell go env GOBIN))
3+
GOBIN=$(shell go env GOPATH)/bin
4+
else
5+
GOBIN=$(shell go env GOBIN)
6+
endif
7+
8+
# Setting SHELL to bash allows bash commands to be executed by recipes.
9+
# This is a requirement for 'setup-envtest.sh' in the test target.
10+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
11+
SHELL = /usr/bin/env bash -o pipefail
12+
.SHELLFLAGS = -ec
13+
14+
all: code mock-gen test
15+
16+
code:
17+
go run generate/generate.go generate/layout.go --api=generate/listApis.json
18+
19+
FILES=$(shell for file in `pwd`/cloudstack/*Service.go ;do basename $$file .go ; done)
20+
mock-gen:
21+
@for f in $(FILES); do \
22+
$(MOCKGEN) -destination=./cloudstack/$${f}_mock.go -package=cloudstack -copyright_file="header.txt" -source=./cloudstack/$${f}.go ; \
23+
done
24+
25+
test:
26+
go test -v ./...
27+
28+
MOCKGEN := $(shell pwd)/bin/mockgen
29+
mockgen: ## Download conversion-gen locally if necessary.
30+
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/mockgen)
31+

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ Last but not the least, there are a lot of helper functions that will try to aut
5757
## Developer Guide
5858

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

6262
```
63-
# Build the generate.go script
64-
cd generate/
65-
go build
66-
67-
# Run the generator to auto-generate the code
68-
./generate -api listApis.json
63+
# Run it via the Makefile
64+
make all
6965
7066
```
7167

cloudstack/APIDiscoveryService.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import (
2424
"net/url"
2525
)
2626

27+
type APIDiscoveryServiceIface interface {
28+
ListApis(p *ListApisParams) (*ListApisResponse, error)
29+
NewListApisParams() *ListApisParams
30+
}
31+
2732
type ListApisParams struct {
2833
p map[string]interface{}
2934
}
@@ -46,6 +51,14 @@ func (p *ListApisParams) SetName(v string) {
4651
p.p["name"] = v
4752
}
4853

54+
func (p *ListApisParams) GetName() (string, bool) {
55+
if p.p == nil {
56+
p.p = make(map[string]interface{})
57+
}
58+
value, ok := p.p["name"].(string)
59+
return value, ok
60+
}
61+
4962
// You should always use this function to get a new ListApisParams instance,
5063
// as then you are sure you have configured all required params
5164
func (s *APIDiscoveryService) NewListApisParams() *ListApisParams {

cloudstack/APIDiscoveryService_mock.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)