Skip to content

Commit

Permalink
Unit Test (#18)
Browse files Browse the repository at this point in the history
* test runs, more fields needed to be test

* tests done, except for kerberos

* keys done, dns waiting

* Complete unit tests for dns_data, dns_config, and keys modules

* Just ran make client

* ran go fmt ./...

* test runs, more fields needed to be test

* tests done, except for kerberos

* keys done, dns waiting

* Complete unit tests for dns_data, dns_config, and keys modules

* Tests

* Unit Tests For Keys, DNS With Generator Working at version 7.3.0

- Unit tests for keys and dns completed, with generator upgraded to 7.3.0
- Ran go fmt ./..., but the equivalence make fmt failed

* Ran 'go fmt ./...' for formatting check and investigated version 7.3.0

* Complete unit tests for ipam, dhcp, dns_data, dns_config, and keys modules

* Complete unit tests for ipam, dhcp, dns_data, dns_config, and keys modules

* Complete unit tests for dns_data, dns_config, and keys modules:
1. Removed the first line in test
2. Updated test object name to camel case

* Complete unit tests for dns_data, dns_config, ipam/dhcp, infra_mgmt and keys modules:
1. Removed the first line in test
2. Updated test object name to camel case

* Complete unit tests for dns_data, dns_config, ipam/dhcp, infra_mgmt and keys modules:
1. Removed the first line in test
2. Updated test object name to camel case
  • Loading branch information
MinJiang00 authored Mar 5, 2024
1 parent f8ac787 commit 395cc8d
Show file tree
Hide file tree
Showing 43 changed files with 4,180 additions and 2,113 deletions.
169 changes: 119 additions & 50 deletions dns_config/test/api_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,158 @@ Testing AclAPIService
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech);

package dns_config
package dns_config_test

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

openapiclient "github.com/infobloxopen/bloxone-go-client/dns_config"
"github.com/infobloxopen/bloxone-go-client/internal"
)

func Test_dns_config_AclAPIService(t *testing.T) {

configuration := internal.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)

t.Run("Test AclAPIService AclCreate", func(t *testing.T) {
var ConfigACLPost = openapiclient.ConfigACL{
Comment: openapiclient.PtrString("This is a dummy ACL for testing."),
Id: openapiclient.PtrString("dummyAclId"),
Name: "dummyAclName",
Tags: make(map[string]interface{}),
}

t.Skip("skip test") // remove to run test
var ConfigACLPatch = openapiclient.ConfigACL{
Comment: openapiclient.PtrString("This is an updated dummy ACL for testing."),
Id: ConfigACLPost.Id,
Name: "updatedDummyAclName",
Tags: make(map[string]interface{}),
}

resp, httpRes, err := apiClient.AclAPI.AclCreate(context.Background()).Execute()
func TestAclAPIService(t *testing.T) {

t.Run("Test AclAPIService AclCreate", func(t *testing.T) {
configuration := internal.NewConfiguration()
configuration.HTTPClient = internal.NewTestClient(func(req *http.Request) *http.Response {
require.Equal(t, http.MethodPost, req.Method)
require.Equal(t, "/api/ddi/v1/dns/acl", req.URL.Path)
require.Equal(t, "application/json", req.Header.Get("Content-Type"))

var reqBody openapiclient.ConfigACL
require.NoError(t, json.NewDecoder(req.Body).Decode(&reqBody))
require.Equal(t, ConfigACLPost, reqBody)

response := openapiclient.ConfigCreateACLResponse{}
body, err := json.Marshal(response)
require.NoError(t, err)

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(body)),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
})
apiClient := openapiclient.NewAPIClient(configuration)
resp, httpRes, err := apiClient.AclAPI.AclCreate(context.Background()).Body(ConfigACLPost).Execute()
require.Nil(t, err)
require.NotNil(t, resp)
assert.Equal(t, 200, httpRes.StatusCode)

})

t.Run("Test AclAPIService AclDelete", func(t *testing.T) {

t.Skip("skip test") // remove to run test

var id string

httpRes, err := apiClient.AclAPI.AclDelete(context.Background(), id).Execute()

require.Nil(t, err)
assert.Equal(t, 200, httpRes.StatusCode)

require.Equal(t, http.StatusOK, httpRes.StatusCode)
})

t.Run("Test AclAPIService AclList", func(t *testing.T) {

t.Skip("skip test") // remove to run test

configuration := internal.NewConfiguration()
configuration.HTTPClient = internal.NewTestClient(func(req *http.Request) *http.Response {
require.Equal(t, http.MethodGet, req.Method)
require.Equal(t, "/api/ddi/v1/dns/acl", req.URL.Path)
require.Equal(t, "application/json", req.Header.Get("Accept"))

response := openapiclient.ConfigListACLResponse{}
body, err := json.Marshal(response)
require.NoError(t, err)

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(body)),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
})
apiClient := openapiclient.NewAPIClient(configuration)
resp, httpRes, err := apiClient.AclAPI.AclList(context.Background()).Execute()

require.Nil(t, err)
require.NotNil(t, resp)
assert.Equal(t, 200, httpRes.StatusCode)

require.Equal(t, http.StatusOK, httpRes.StatusCode)
})

t.Run("Test AclAPIService AclRead", func(t *testing.T) {

t.Skip("skip test") // remove to run test

var id string

resp, httpRes, err := apiClient.AclAPI.AclRead(context.Background(), id).Execute()

configuration := internal.NewConfiguration()
configuration.HTTPClient = internal.NewTestClient(func(req *http.Request) *http.Response {
require.Equal(t, http.MethodGet, req.Method)
require.Equal(t, "/api/ddi/v1/dns/acl/"+*ConfigACLPost.Id, req.URL.Path)
require.Equal(t, "application/json", req.Header.Get("Accept"))

response := openapiclient.ConfigReadACLResponse{}
body, err := json.Marshal(response)
require.NoError(t, err)

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(body)),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
})
apiClient := openapiclient.NewAPIClient(configuration)
resp, httpRes, err := apiClient.AclAPI.AclRead(context.Background(), *ConfigACLPost.Id).Execute()
require.Nil(t, err)
require.NotNil(t, resp)
assert.Equal(t, 200, httpRes.StatusCode)

require.Equal(t, http.StatusOK, httpRes.StatusCode)
})

t.Run("Test AclAPIService AclUpdate", func(t *testing.T) {

t.Skip("skip test") // remove to run test

var id string

resp, httpRes, err := apiClient.AclAPI.AclUpdate(context.Background(), id).Execute()

configuration := internal.NewConfiguration()
configuration.HTTPClient = internal.NewTestClient(func(req *http.Request) *http.Response {
require.Equal(t, http.MethodPatch, req.Method)
require.Equal(t, "/api/ddi/v1/dns/acl/"+*ConfigACLPost.Id, req.URL.Path)
require.Equal(t, "application/json", req.Header.Get("Content-Type"))

var reqBody openapiclient.ConfigACL
require.NoError(t, json.NewDecoder(req.Body).Decode(&reqBody))
require.Equal(t, ConfigACLPatch, reqBody)

response := openapiclient.ConfigUpdateACLResponse{}
body, err := json.Marshal(response)
require.NoError(t, err)

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(body)),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
})
apiClient := openapiclient.NewAPIClient(configuration)
resp, httpRes, err := apiClient.AclAPI.AclUpdate(context.Background(), *ConfigACLPatch.Id).Body(ConfigACLPatch).Execute()
require.Nil(t, err)
require.NotNil(t, resp)
assert.Equal(t, 200, httpRes.StatusCode)
require.Equal(t, http.StatusOK, httpRes.StatusCode)
})

t.Run("Test AclAPIService AclDelete", func(t *testing.T) {
configuration := internal.NewConfiguration()
configuration.HTTPClient = internal.NewTestClient(func(req *http.Request) *http.Response {
require.Equal(t, http.MethodDelete, req.Method)
require.Equal(t, "/api/ddi/v1/dns/acl/"+*ConfigACLPost.Id, req.URL.Path)

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader([]byte{})),
Header: map[string][]string{"Content-Type": {"application/json"}},
}
})
apiClient := openapiclient.NewAPIClient(configuration)
httpRes, err := apiClient.AclAPI.AclDelete(context.Background(), *ConfigACLPost.Id).Execute()
require.Nil(t, err)
require.Equal(t, http.StatusOK, httpRes.StatusCode)
})

}
Loading

0 comments on commit 395cc8d

Please sign in to comment.