Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Continue adding usage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcantera committed Nov 7, 2022
1 parent 4b29e1a commit 1de428c
Show file tree
Hide file tree
Showing 97 changed files with 4,016 additions and 1,853 deletions.
6 changes: 3 additions & 3 deletions api/api_client_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
package api

import (
"context"
"github.com/ingrammicro/cio/logger"
"github.com/ingrammicro/cio/types"
"golang.org/x/net/context"
)

// ListEvents returns the list of events as an array of Event
func (imco *ClientAPI) ListEvents(ctx context.Context) (events []*types.Event, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, pathAuditEvents, true, &events)
_, err = imco.GetAndCheck(ctx, PathAuditEvents, true, &events)
if err != nil {
return nil, err
}
Expand All @@ -23,7 +23,7 @@ func (imco *ClientAPI) ListEvents(ctx context.Context) (events []*types.Event, e
func (imco *ClientAPI) ListSysEvents(ctx context.Context) (events []*types.Event, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, pathAuditSystemEvents, true, &events)
_, err = imco.GetAndCheck(ctx, PathAuditSystemEvents, true, &events)
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions api/api_client_audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"fmt"
"github.com/ingrammicro/cio/internal/testutils"
"github.com/ingrammicro/cio/types"
"net/http"
"net/http/httptest"
Expand All @@ -13,12 +14,12 @@ import (

func TestListEvents(t *testing.T) {
tests := map[string]struct {
expected interface{}
expected any
server *httptest.Server
}{
"if defined endpoint for API service is resolving properly": {
expected: []*types.Event{},
server: NewServer(http.StatusOK, []*types.Event{}),
server: testutils.NewServer(http.StatusOK, []*types.Event{}),
},
"if defined endpoint for API service is invalid or cannot be reached": {
expected: "Cannot execute request",
Expand Down Expand Up @@ -53,12 +54,12 @@ func TestListEvents(t *testing.T) {

func TestListSysEvents(t *testing.T) {
tests := map[string]struct {
expected interface{}
expected any
server *httptest.Server
}{
"if defined endpoint for API service is resolving properly": {
expected: []*types.Event{},
server: NewServer(http.StatusOK, []*types.Event{}),
server: testutils.NewServer(http.StatusOK, []*types.Event{}),
},
"if defined endpoint for API service is invalid or cannot be reached": {
expected: "Cannot execute request",
Expand Down
58 changes: 29 additions & 29 deletions api/api_client_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
package api

import (
"context"
"fmt"
"github.com/ingrammicro/cio/logger"
"github.com/ingrammicro/cio/types"
"golang.org/x/net/context"
)

// GetAttachment returns a attachment by its ID
func (imco *ClientAPI) GetAttachment(ctx context.Context, attachmentID string,
) (attachment *types.Attachment, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintAttachment, attachmentID), true, &attachment)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintAttachment, attachmentID), true, &attachment)
if err != nil {
return nil, err
}
Expand All @@ -25,7 +25,7 @@ func (imco *ClientAPI) GetAttachment(ctx context.Context, attachmentID string,
func (imco *ClientAPI) DeleteAttachment(ctx context.Context, attachmentID string) (err error) {
logger.DebugFuncInfo()

_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(pathBlueprintAttachment, attachmentID), true, nil)
_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(PathBlueprintAttachment, attachmentID), true, nil)
if err != nil {
return err
}
Expand All @@ -37,7 +37,7 @@ func (imco *ClientAPI) ListCookbookVersions(ctx context.Context,
) (cookbookVersions []*types.CookbookVersion, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, pathBlueprintCookbookVersions, true, &cookbookVersions)
_, err = imco.GetAndCheck(ctx, PathBlueprintCookbookVersions, true, &cookbookVersions)
if err != nil {
return nil, err
}
Expand All @@ -49,7 +49,7 @@ func (imco *ClientAPI) GetCookbookVersion(ctx context.Context, cookbookVersionID
) (cookbookVersion *types.CookbookVersion, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintCookbookVersion, cookbookVersionID), true, &cookbookVersion)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintCookbookVersion, cookbookVersionID), true, &cookbookVersion)
if err != nil {
return nil, err
}
Expand All @@ -61,7 +61,7 @@ func (imco *ClientAPI) CreateCookbookVersion(ctx context.Context, cookbookVersio
) (cookbookVersion *types.CookbookVersion, err error) {
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx, pathBlueprintCookbookVersions, cookbookVersionParams, true, &cookbookVersion)
_, err = imco.PostAndCheck(ctx, PathBlueprintCookbookVersions, cookbookVersionParams, true, &cookbookVersion)
if err != nil {
return nil, err
}
Expand All @@ -75,7 +75,7 @@ func (imco *ClientAPI) ProcessCookbookVersion(ctx context.Context, cookbookVersi
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx,
fmt.Sprintf(pathBlueprintCookbookVersionProcess, cookbookVersionID),
fmt.Sprintf(PathBlueprintCookbookVersionProcess, cookbookVersionID),
cookbookVersionParams,
true,
&cookbookVersion,
Expand All @@ -90,7 +90,7 @@ func (imco *ClientAPI) ProcessCookbookVersion(ctx context.Context, cookbookVersi
func (imco *ClientAPI) DeleteCookbookVersion(ctx context.Context, cookbookVersionID string) (err error) {
logger.DebugFuncInfo()

_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(pathBlueprintCookbookVersion, cookbookVersionID), true, nil)
_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(PathBlueprintCookbookVersion, cookbookVersionID), true, nil)
if err != nil {
return err
}
Expand All @@ -101,7 +101,7 @@ func (imco *ClientAPI) DeleteCookbookVersion(ctx context.Context, cookbookVersio
func (imco *ClientAPI) ListScripts(ctx context.Context) (scripts []*types.Script, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, pathBlueprintScripts, true, &scripts)
_, err = imco.GetAndCheck(ctx, PathBlueprintScripts, true, &scripts)
if err != nil {
return nil, err
}
Expand All @@ -112,7 +112,7 @@ func (imco *ClientAPI) ListScripts(ctx context.Context) (scripts []*types.Script
func (imco *ClientAPI) GetScript(ctx context.Context, scriptID string) (script *types.Script, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintScript, scriptID), true, &script)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintScript, scriptID), true, &script)
if err != nil {
return nil, err
}
Expand All @@ -124,7 +124,7 @@ func (imco *ClientAPI) CreateScript(ctx context.Context, scriptParams *map[strin
) (script *types.Script, err error) {
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx, pathBlueprintScripts, scriptParams, true, &script)
_, err = imco.PostAndCheck(ctx, PathBlueprintScripts, scriptParams, true, &script)
if err != nil {
return nil, err
}
Expand All @@ -136,7 +136,7 @@ func (imco *ClientAPI) UpdateScript(ctx context.Context, scriptID string, script
) (script *types.Script, err error) {
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx, fmt.Sprintf(pathBlueprintScript, scriptID), scriptParams, true, &script)
_, err = imco.PutAndCheck(ctx, fmt.Sprintf(PathBlueprintScript, scriptID), scriptParams, true, &script)
if err != nil {
return nil, err
}
Expand All @@ -147,7 +147,7 @@ func (imco *ClientAPI) UpdateScript(ctx context.Context, scriptID string, script
func (imco *ClientAPI) DeleteScript(ctx context.Context, scriptID string) (err error) {
logger.DebugFuncInfo()

_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(pathBlueprintScript, scriptID), true, nil)
_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(PathBlueprintScript, scriptID), true, nil)
if err != nil {
return err
}
Expand All @@ -159,7 +159,7 @@ func (imco *ClientAPI) AddScriptAttachment(ctx context.Context, scriptID string,
) (attachment *types.Attachment, err error) {
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx, fmt.Sprintf(pathBlueprintScriptAttachments, scriptID), attachmentIn, true, &attachment)
_, err = imco.PostAndCheck(ctx, fmt.Sprintf(PathBlueprintScriptAttachments, scriptID), attachmentIn, true, &attachment)
if err != nil {
return nil, err
}
Expand All @@ -173,7 +173,7 @@ func (imco *ClientAPI) UploadedScriptAttachment(ctx context.Context, attachmentI
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx,
fmt.Sprintf(pathBlueprintAttachmentUploaded, attachmentID),
fmt.Sprintf(PathBlueprintAttachmentUploaded, attachmentID),
attachmentParams,
true,
&attachment,
Expand All @@ -189,7 +189,7 @@ func (imco *ClientAPI) ListScriptAttachments(ctx context.Context, scriptID strin
) (attachments []*types.Attachment, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintScriptAttachments, scriptID), true, &attachments)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintScriptAttachments, scriptID), true, &attachments)
if err != nil {
return nil, err
}
Expand All @@ -200,7 +200,7 @@ func (imco *ClientAPI) ListScriptAttachments(ctx context.Context, scriptID strin
func (imco *ClientAPI) ListTemplates(ctx context.Context) (templates []*types.Template, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, pathBlueprintTemplates, true, &templates)
_, err = imco.GetAndCheck(ctx, PathBlueprintTemplates, true, &templates)
if err != nil {
return nil, err
}
Expand All @@ -211,7 +211,7 @@ func (imco *ClientAPI) ListTemplates(ctx context.Context) (templates []*types.Te
func (imco *ClientAPI) GetTemplate(ctx context.Context, templateID string) (template *types.Template, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplate, templateID), true, &template)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplate, templateID), true, &template)
if err != nil {
return nil, err
}
Expand All @@ -223,7 +223,7 @@ func (imco *ClientAPI) CreateTemplate(ctx context.Context, templateParams *map[s
) (template *types.Template, err error) {
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx, pathBlueprintTemplates, templateParams, true, &template)
_, err = imco.PostAndCheck(ctx, PathBlueprintTemplates, templateParams, true, &template)
if err != nil {
return nil, err
}
Expand All @@ -235,7 +235,7 @@ func (imco *ClientAPI) UpdateTemplate(ctx context.Context, templateID string, te
) (template *types.Template, err error) {
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplate, templateID), templateParams, true, &template)
_, err = imco.PutAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplate, templateID), templateParams, true, &template)
if err != nil {
return nil, err
}
Expand All @@ -247,7 +247,7 @@ func (imco *ClientAPI) CompileTemplate(ctx context.Context, templateID string, p
) (template *types.Template, err error) {
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplateCompile, templateID), payload, true, &template)
_, err = imco.PutAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplateCompile, templateID), payload, true, &template)
if err != nil {
return nil, err
}
Expand All @@ -258,7 +258,7 @@ func (imco *ClientAPI) CompileTemplate(ctx context.Context, templateID string, p
func (imco *ClientAPI) DeleteTemplate(ctx context.Context, templateID string) (err error) {
logger.DebugFuncInfo()

_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplate, templateID), true, nil)
_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplate, templateID), true, nil)
if err != nil {
return err
}
Expand All @@ -271,7 +271,7 @@ func (imco *ClientAPI) ListTemplateScripts(ctx context.Context, templateID strin
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx,
fmt.Sprintf(pathBlueprintTemplateScriptsType, templateID, scriptType),
fmt.Sprintf(PathBlueprintTemplateScriptsType, templateID, scriptType),
true,
&templateScript,
)
Expand All @@ -287,7 +287,7 @@ func (imco *ClientAPI) GetTemplateScript(ctx context.Context, templateID string,
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx,
fmt.Sprintf(pathBlueprintTemplateScript, templateID, templateScriptID),
fmt.Sprintf(PathBlueprintTemplateScript, templateID, templateScriptID),
true,
&templateScript,
)
Expand All @@ -304,7 +304,7 @@ func (imco *ClientAPI) CreateTemplateScript(ctx context.Context, templateID stri
logger.DebugFuncInfo()

_, err = imco.PostAndCheck(ctx,
fmt.Sprintf(pathBlueprintTemplateScripts, templateID),
fmt.Sprintf(PathBlueprintTemplateScripts, templateID),
templateScriptParams,
true,
&templateScript,
Expand All @@ -322,7 +322,7 @@ func (imco *ClientAPI) UpdateTemplateScript(ctx context.Context, templateID stri
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx,
fmt.Sprintf(pathBlueprintTemplateScript, templateID, templateScriptID),
fmt.Sprintf(PathBlueprintTemplateScript, templateID, templateScriptID),
templateScriptParams,
true,
&templateScript,
Expand All @@ -338,7 +338,7 @@ func (imco *ClientAPI) DeleteTemplateScript(ctx context.Context, templateID stri
) (err error) {
logger.DebugFuncInfo()

_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplateScript, templateID, templateScriptID), true, nil)
_, err = imco.DeleteAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplateScript, templateID, templateScriptID), true, nil)
if err != nil {
return err
}
Expand All @@ -352,7 +352,7 @@ func (imco *ClientAPI) ReorderTemplateScript(ctx context.Context, templateID str
logger.DebugFuncInfo()

_, err = imco.PutAndCheck(ctx,
fmt.Sprintf(pathBlueprintTemplateScriptsReorder, templateID),
fmt.Sprintf(PathBlueprintTemplateScriptsReorder, templateID),
templateScriptParams,
true,
&templateScript,
Expand All @@ -368,7 +368,7 @@ func (imco *ClientAPI) ListTemplateServers(ctx context.Context, templateID strin
) (templateServer []*types.TemplateServer, err error) {
logger.DebugFuncInfo()

_, err = imco.GetAndCheck(ctx, fmt.Sprintf(pathBlueprintTemplateServers, templateID), true, &templateServer)
_, err = imco.GetAndCheck(ctx, fmt.Sprintf(PathBlueprintTemplateServers, templateID), true, &templateServer)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 1de428c

Please sign in to comment.