Skip to content
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
56 changes: 37 additions & 19 deletions pkg/services/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package services

import (
"path/filepath"
"reflect"
"testing"

Expand All @@ -13,8 +14,8 @@ import (
)

var (
accountsGetResponse = testlib.Fixture("testdata/authorization/accounts/get.json")
accountsGetAllResponse = testlib.Fixture("testdata/authorization/accounts/getall.json")
accountsGetSuccess = "authorization/accounts/get.success.json"
accountsGetAllSuccess = "authorization/accounts/getall.success.json"
)

func setupAccountService() *AccountService {
Expand All @@ -27,12 +28,17 @@ func TestAccountGetAll(t *testing.T) {
svc := setupAccountService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/authorization/accounts", accountsGetAllResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, accountsGetAllSuccess),
)
testlib.AddGetResponseToMux("/authorization/accounts", response, 0)

res, err := svc.GetAll()
res, err := svc.GetAll()

assert.Nil(t, err)
assert.Equal(t, 2, len(res))
assert.Nil(t, err)
assert.Equal(t, 2, len(res))
}
}

func TestAccountGetAllError(t *testing.T) {
Expand All @@ -51,14 +57,20 @@ func TestAccountGet(t *testing.T) {
svc := setupAccountService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/authorization/accounts/{id}", accountsGetResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, accountsGetSuccess),
)

res, err := svc.Get("ID")
testlib.AddGetResponseToMux("/authorization/accounts/{id}", response, 0)

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Account)(nil)), reflect.TypeOf(res))
assert.True(t, res.Id != "")
res, err := svc.Get("ID")

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Account)(nil)), reflect.TypeOf(res))
assert.True(t, res.Id != "")
}
}

func TestAccountGetError(t *testing.T) {
Expand All @@ -77,15 +89,21 @@ func TestAccountGetByName(t *testing.T) {
svc := setupAccountService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/authorization/accounts", accountsGetAllResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, accountsGetAllSuccess),
)
testlib.AddGetResponseToMux("/authorization/accounts", response, 0)

res, err := svc.GetByName("admin@pronghorn")
res, err := svc.GetByName("admin@pronghorn")

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Account)(nil)), reflect.TypeOf(res))
assert.True(t, res.Id != "")
assert.True(t, res.Username == "admin@pronghorn")
assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Account)(nil)), reflect.TypeOf(res))
assert.True(t, res.Id != "")
assert.True(t, res.Username == "admin@pronghorn")

}
}

func TestAccountGetByNameError(t *testing.T) {
Expand Down
17 changes: 12 additions & 5 deletions pkg/services/adapter_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
package services

import (
"path/filepath"
"testing"

"github.com/itential/ipctl/internal/testlib"
"github.com/stretchr/testify/assert"
)

var (
adapterModelsGetAllResponse = testlib.Fixture("testdata/adapter-models/getall.json")
adapterModelsGetAllSuccess = "adapter-models/getall.success.json"
)

func setupAdapterModelService() *AdapterModelService {
Expand All @@ -25,10 +26,16 @@ func TestAdapterModelsGetAll(t *testing.T) {
svc := setupAdapterModelService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/adapter-models/types", adapterModelsGetAllResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, adapterModelsGetAllSuccess),
)

res, err := svc.GetAll()
testlib.AddGetResponseToMux("/adapter-models/types", response, 0)

assert.Nil(t, err)
assert.Equal(t, 7, len(res))
res, err := svc.GetAll()

assert.Nil(t, err)
assert.Equal(t, 7, len(res))
}
}
37 changes: 25 additions & 12 deletions pkg/services/adapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package services

import (
"path/filepath"
"reflect"
"testing"

Expand All @@ -13,8 +14,8 @@ import (
)

var (
adaptersGetResponse = testlib.Fixture("testdata/adapters/get.json")
adaptersGetAllResponse = testlib.Fixture("testdata/adapters/getall.json")
adaptersGetSuccess = "adapters/get.success.json"
adaptersGetAllSuccess = "adapters/getall.success.json"
)

func setupAdapterService() *AdapterService {
Expand All @@ -27,26 +28,38 @@ func TestAdaptersGetAll(t *testing.T) {
svc := setupAdapterService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/adapters", adaptersGetAllResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, adaptersGetAllSuccess),
)

res, err := svc.GetAll()
testlib.AddGetResponseToMux("/adapters", response, 0)

assert.Nil(t, err)
assert.Equal(t, 1, len(res))
res, err := svc.GetAll()

assert.Nil(t, err)
assert.Equal(t, 1, len(res))
}
}

func TestAdapterGet(t *testing.T) {
svc := setupAdapterService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/adapters/{name}", adaptersGetResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, adaptersGetSuccess),
)

res, err := svc.Get("local_aaa")
testlib.AddGetResponseToMux("/adapters/{name}", response, 0)

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Adapter)(nil)), reflect.TypeOf(res))
assert.True(t, res.Name == "local_aaa")
res, err := svc.Get("local_aaa")

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Adapter)(nil)), reflect.TypeOf(res))
assert.True(t, res.Name == "local_aaa")
}
}

func TestAdapterGetError(t *testing.T) {
Expand Down
39 changes: 26 additions & 13 deletions pkg/services/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package services

import (
"path/filepath"
"reflect"
"testing"

Expand All @@ -13,8 +14,8 @@ import (
)

var (
applicationsGetAllResponse = testlib.Fixture("testdata/applications/getall.json")
applicationsGetResponse = testlib.Fixture("testdata/applications/get.json")
applicationsGetAllSuccess = "applications/getall.success.json"
applicationsGetSuccess = "applications/get.success.json"
)

func setupApplicationService() *ApplicationService {
Expand All @@ -27,25 +28,37 @@ func TestApplicationsGetAll(t *testing.T) {
svc := setupApplicationService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/applications", applicationsGetAllResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, applicationsGetAllSuccess),
)

res, err := svc.GetAll()
testlib.AddGetResponseToMux("/applications", response, 0)

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, 18, len(res))
res, err := svc.GetAll()

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, 18, len(res))
}
}

func TestApplicationsGet(t *testing.T) {
svc := setupApplicationService()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/applications/WorkFlowEngine", applicationsGetResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, applicationsGetSuccess),
)

testlib.AddGetResponseToMux("/applications/WorkFlowEngine", response, 0)

res, err := svc.Get("WorkFlowEngine")
res, err := svc.Get("WorkFlowEngine")

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Application)(nil)), reflect.TypeOf(res))
assert.Equal(t, "WorkFlowEngine", res.Name)
assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, reflect.TypeOf((*Application)(nil)), reflect.TypeOf(res))
assert.Equal(t, "WorkFlowEngine", res.Name)
}
}
19 changes: 13 additions & 6 deletions pkg/services/current_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@
package services

import (
"path/filepath"
"testing"

"github.com/itential/ipctl/internal/testlib"
"github.com/stretchr/testify/assert"
)

var (
getCurrentUserResponse = testlib.Fixture("testdata/whoami.json")
getCurrentUserSuccess = "whoami.success.json"
)

func TestGetCurrentUser(t *testing.T) {
testClient := testlib.Setup()
defer testlib.Teardown()

testlib.AddGetResponseToMux("/whoami", getCurrentUserResponse, 0)
for _, ele := range fixtureSuites {
response := testlib.Fixture(
filepath.Join(fixtureRoot, ele, getCurrentUserSuccess),
)

res, err := GetCurrentUser(testClient)
testlib.AddGetResponseToMux("/whoami", response, 0)

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, "admin@pronghorn", res.Username)
res, err := GetCurrentUser(testClient)

assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, "admin@pronghorn", res.Username)
}
}
Loading