Skip to content

Commit

Permalink
Create auto-generated objects.go file (infobloxopen#178)
Browse files Browse the repository at this point in the history
This branch contains newly added object structures of WAPI with generator code , where object_generated.go is created for applying the changes. 

For some fields with omitempty, where some cases with updating empty is not considered as update introduced pointers. 

Added E2E tests for functional validation of objects generated


Co-authored-by: Sergey Kudriavtsev <[email protected]>
Co-authored-by: hemanthKa677 <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2023
1 parent e439cee commit 072a0c8
Show file tree
Hide file tree
Showing 236 changed files with 46,868 additions and 12,131 deletions.
1,161 changes: 1,161 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

61 changes: 0 additions & 61 deletions CHANGELOG.rst

This file was deleted.

21 changes: 21 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,31 @@ func (wrb *WapiRequestBuilder) BuildUrl(t RequestType, objType string, ref strin
return u.String()
}

// populateNilLists fills nil lists in IBObject structs, since NIOS doesn't accept a null list in JSON payload.
func (wrb *WapiRequestBuilder) populateNilLists(obj IBObject) IBObject {
objVal := reflect.ValueOf(obj)
if reflect.ValueOf(obj).Kind() == reflect.Ptr {
objVal = objVal.Elem()
}

for i := 0; i < objVal.NumField(); i++ {
fieldVal := objVal.Field(i)
if fieldVal.Type().Kind() == reflect.Slice && fieldVal.CanSet() {
if fieldVal.IsNil() == true {
fieldVal.Set(reflect.MakeSlice(fieldVal.Type(), 0, 0))
}
}
}

return obj
}

func (wrb *WapiRequestBuilder) BuildBody(t RequestType, obj IBObject) []byte {
var objJSON []byte
var err error

obj = wrb.populateNilLists(obj)

objJSON, err = json.Marshal(obj)
if err != nil {
log.Printf("Cannot marshal object '%s': %s", obj, err)
Expand Down
2 changes: 1 addition & 1 deletion connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
29 changes: 29 additions & 0 deletions e2e_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# End-to-end tests

This set of tests is intended for functionality validation on an existing WAPI
instance.

## How to run E2E tests

1. Export parameters of accessible and running `WAPI` instance:
```bash
export INFOBLOX_SERVER=<WAPI HOST IP> INFOBLOX_USERNAME=<WAPI USERNAME> INFOBLOX_PASSWORD=<WAPI PASSWORD> WAPI_VERSION=<WAPI VERSION>
```

2. You can use `go test` utility to run the tests in the `e2e_tests` directory:
```bash
go test -v ./e2e_tests
```

3. Instead of `go test` you can also use the [`ginkgo`](https://onsi.github.io/ginkgo/#installing-ginkgo) utility,
which supports test filtering by label, and lots of [additional features](https://onsi.github.io/ginkgo/#running-specs):
```bash
# Run all e2e tests
ginkgo e2e_tests
# Run only read-only e2e tests
ginkgo --label-filter=RO e2e_tests
```

## Warning

Please don't run those tests on the production WAPI instance.
Loading

0 comments on commit 072a0c8

Please sign in to comment.