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

Commit

Permalink
Migrate to cobra (issue #46)
Browse files Browse the repository at this point in the history
Closes #46
  • Loading branch information
pcantera committed Oct 10, 2022
1 parent 1f5b1c1 commit fc37b19
Show file tree
Hide file tree
Showing 469 changed files with 18,561 additions and 50,739 deletions.
27 changes: 20 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- main: main.go
binary: cio
- binary: cio
env:
- CGO_ENABLED=0
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
archive:
name_template: "{{ .ProjectName }}.{{ .Arch }}.{{ .Os }}"
format: binary
archives:
- format: binary
name_template: "{{ .ProjectName }}.{{ .Version }}.{{ .Arch }}.{{ .Os }}"
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
release:
prerelease: false
name_template: "{{.ProjectName}}-v{{.Version}}"
prerelease: auto
name_template: "{{.ProjectName}} {{.Tag}}"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

37 changes: 0 additions & 37 deletions agentsecret/agentsecret.go

This file was deleted.

42 changes: 0 additions & 42 deletions api/agentsecret/secret_api.go

This file was deleted.

55 changes: 0 additions & 55 deletions api/agentsecret/secret_api_mocked.go

This file was deleted.

10 changes: 0 additions & 10 deletions api/agentsecret/secret_api_test.go

This file was deleted.

31 changes: 31 additions & 0 deletions api/api_client_audit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2017-2022 Ingram Micro Inc.

package api

import (
"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)
if err != nil {
return nil, err
}
return events, nil
}

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

_, err = imco.GetAndCheck(ctx, pathAuditSystemEvents, true, &events)
if err != nil {
return nil, err
}
return events, nil
}
95 changes: 95 additions & 0 deletions api/api_client_audit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package api

import (
"context"
"fmt"
"github.com/ingrammicro/cio/types"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"
)

func TestListEvents(t *testing.T) {
tests := map[string]struct {
expected interface{}
server *httptest.Server
}{

"if defined endpoint for API service is resolving properly": {
expected: []*types.Event{},
server: NewServer(http.StatusOK, []*types.Event{}),
},
"if defined endpoint for API service is invalid or cannot be reached": {
expected: "Cannot execute request",
server: nil,
},
}

config, svc, err := InitConfigAndClientAPI()
if err != nil {
t.Errorf("Failed. Unexpected error: %v\n", err)
return
}

for title, test := range tests {
t.Logf("ListEvents: %v\n", title)
t.Run(title, func(t *testing.T) {
if test.server != nil {
server := test.server
defer server.Close()
config.APIEndpoint = server.URL + pathAuditEvents
}

events, err := svc.ListEvents(context.Background())
if err != nil && !strings.Contains(err.Error(), fmt.Sprintf("%s", test.expected)) {
t.Errorf("Failed. Unexpected error: %v\n", err)
}
if err == nil && !reflect.DeepEqual(events, test.expected) {
t.Errorf("Failed. Unexpected response: %v\n", events)
}
})
}
}

func TestListSysEvents(t *testing.T) {
tests := map[string]struct {
expected interface{}
server *httptest.Server
}{
"if defined endpoint for API service is resolving properly": {
expected: []*types.Event{},
server: NewServer(http.StatusOK, []*types.Event{}),
},
"if defined endpoint for API service is invalid or cannot be reached": {
expected: "Cannot execute request",
server: nil,
},
}

config, svc, err := InitConfigAndClientAPI()
if err != nil {
t.Errorf("Failed. Unexpected error: %v\n", err)
return
}

for title, test := range tests {
t.Logf("ListSysEvents: %v\n", title)
t.Run(title, func(t *testing.T) {
if test.server != nil {
server := test.server
defer server.Close()
config.APIEndpoint = server.URL + pathAuditSystemEvents
}

events, err := svc.ListSysEvents(context.Background())
if err != nil && !strings.Contains(err.Error(), fmt.Sprintf("%s", test.expected)) {
t.Errorf("Failed. Unexpected error: %v\n", err)
}
if err == nil && !reflect.DeepEqual(events, test.expected) {
t.Errorf("Failed. Unexpected response: %v\n", events)
}
})
}
}
Loading

0 comments on commit fc37b19

Please sign in to comment.