Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Resource Implementation #98

Merged
merged 22 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 96 additions & 24 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -274,7 +277,7 @@
}

defer func() error {
if err := file.Close(); err != nil {

Check warning on line 280 in deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

if-return: redundant if ...; err != nil check, just return error instead. (revive)
return err
}
return nil
Expand Down Expand Up @@ -304,7 +307,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -363,7 +369,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}

} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
Expand All @@ -377,7 +386,7 @@
return packageParam, httpRespError
}

responseString, error := extractString(httpResp)

Check warning on line 389 in deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return packageParam, fmt.Errorf("Error Extracting Response: %s", error)
}
Expand All @@ -385,7 +394,10 @@
if httpResp.StatusCode == 200 {

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return packageParam, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

err := json.Unmarshal([]byte(responseString), &packageParam)
Expand All @@ -411,7 +423,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand All @@ -423,7 +438,7 @@
return &gatewayResponse, httpRespError
}

responseString, error := extractString(httpResp)

Check warning on line 441 in deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error)
}
Expand All @@ -444,7 +459,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

var mdmTopologyDetails types.MDMTopologyDetails
Expand Down Expand Up @@ -473,7 +491,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand All @@ -485,7 +506,7 @@
return &gatewayResponse, httpRespError
}

responseString, error := extractString(httpResp)

Check warning on line 509 in deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error)
}
Expand All @@ -506,7 +527,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

if requireJSONOutput {
Expand Down Expand Up @@ -544,7 +568,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand All @@ -556,7 +583,7 @@
return &gatewayResponse, httpRespError
}

responseString, error := extractString(httpResp)

Check warning on line 586 in deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error)
}
Expand All @@ -573,7 +600,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand Down Expand Up @@ -631,7 +661,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -677,7 +710,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -707,7 +743,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand All @@ -727,7 +766,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -757,7 +799,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand All @@ -777,7 +822,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -807,7 +855,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand All @@ -827,7 +878,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -857,7 +911,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand All @@ -877,7 +934,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down Expand Up @@ -907,7 +967,10 @@
}

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return &gatewayResponse, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

gatewayResponse.StatusCode = 200
Expand All @@ -927,7 +990,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand All @@ -947,7 +1013,10 @@
if httpResp.StatusCode == 200 {

if gc.version == "4.0" {
storeCookie(httpResp.Header, gc.host)
err := storeCookie(httpResp.Header, gc.host)
if err != nil {
return mdmQueueCommandDetails, fmt.Errorf("Error While Storing cookie: %s", err)
}
}

var queueCommandDetails map[string][]interface{}
Expand Down Expand Up @@ -1047,7 +1116,10 @@
if gc.version == "4.0" {
req.Header.Set("Authorization", "Bearer "+gc.token)

setCookie(req.Header, gc.host)
err := setCookie(req.Header, gc.host)
if err != nil {
return nil, fmt.Errorf("Error While Handling Cookie: %s", err)
}
} else {
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password)))
}
Expand Down
19 changes: 9 additions & 10 deletions inttests/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,46 @@ import (
)

func TestGetNodes(t *testing.T) {
allNodes, err := C.GetAllNodes()
allNodes, err := GC.GetAllNodes()
assert.Nil(t, err)
assert.NotNil(t, allNodes)
}

func TestGetNodeByID(t *testing.T) {
allNodes, err := C.GetAllNodes()
allNodes, err := GC.GetAllNodes()
assert.Nil(t, err)
assert.NotNil(t, allNodes)

if len(allNodes) > 0 {
node, err := C.GetNodeByID(allNodes[0].RefID)
node, err := GC.GetNodeByID(allNodes[0].RefID)
assert.Nil(t, err)
assert.NotNil(t, node)
}

node, err := C.GetNodeByID(invalidIdentifier)
node, err := GC.GetNodeByID(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, node)
}

func TestGetNodeByFilters(t *testing.T) {
allNodes, err := C.GetNodeByFilters("invalid", "invalid")
allNodes, err := GC.GetNodeByFilters("invalid", "invalid")
assert.NotNil(t, err)
assert.Nil(t, allNodes)
}

func TestGetNodePoolByID(t *testing.T) {
nodePool, err := C.GetNodePoolByID(-2)
assert.Nil(t, err)
assert.Equal(t, nodePool.DeviceGroup.GroupName, "")
_, err := GC.GetNodePoolByID(-2)
assert.NotNil(t, err)
}

func TestGetNodePoolByName(t *testing.T) {
nodePool, err := C.GetNodePoolByName(invalidIdentifier)
nodePool, err := GC.GetNodePoolByName(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, nodePool)
}

func TestGetAllNodePools(t *testing.T) {
allNodePools, err := C.GetAllNodePools()
allNodePools, err := GC.GetAllNodePools()
assert.Nil(t, err)
assert.NotNil(t, allNodePools)
}
Loading
Loading