mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-11-15 20:23:10 +00:00
fix: test packages
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package awsmodel
|
||||
|
||||
// Hooks for the external test package.
|
||||
var ParseSmithyModel = parseSmithyModel
|
||||
|
||||
func (m *Model) OperationErrorCodes(operation *Operation) []string {
|
||||
return m.operationErrorCodes(operation)
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package awsmodel
|
||||
package awsmodel_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/mulgadc/spinifex/internal/awsmodel"
|
||||
)
|
||||
|
||||
func mustLoad(t *testing.T, service Service) *Model {
|
||||
@@ -107,7 +109,7 @@ func TestSmithyErrors(t *testing.T) {
|
||||
// JSON wire code stays the shape name.
|
||||
acm := mustLoad(t, ACM)
|
||||
deleteCertificate, _ := acm.Operation("DeleteCertificate")
|
||||
codes := acm.operationErrorCodes(deleteCertificate)
|
||||
codes := acm.OperationErrorCodes(deleteCertificate)
|
||||
if !strings.Contains(strings.Join(codes, ","), "AccessDeniedException") {
|
||||
t.Errorf("DeleteCertificate codes = %v, want AccessDeniedException", codes)
|
||||
}
|
||||
@@ -184,7 +186,7 @@ func TestParseSmithyModelRejectsMalformedModels(t *testing.T) {
|
||||
}
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, err := parseSmithyModel("test", []byte(test.document))
|
||||
_, err := ParseSmithyModel("test", []byte(test.document))
|
||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("error = %v, want it to contain %q", err, test.want)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package gateway_iam
|
||||
package gateway_iam_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -7,14 +7,18 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/iam"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
gateway_iam "github.com/mulgadc/spinifex/spinifex/gateway/iam"
|
||||
handlers_iam "github.com/mulgadc/spinifex/spinifex/handlers/iam"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const testAccountID = "000000000000"
|
||||
|
||||
// listStub serves fixed lists in whatever order the test gives, as the KV
|
||||
// bucket does, and counts service calls.
|
||||
type listStub struct {
|
||||
stubIAMService
|
||||
handlers_iam.IAMService
|
||||
|
||||
users []string
|
||||
versions []string
|
||||
@@ -53,7 +57,7 @@ func userNames(users []*iam.User) []string {
|
||||
|
||||
func listUsers(t *testing.T, svc *listStub, marker *string, maxItems int64) *iam.ListUsersOutput {
|
||||
t.Helper()
|
||||
out, err := ListUsers(testAccountID, &iam.ListUsersInput{Marker: marker, MaxItems: aws.Int64(maxItems)}, svc)
|
||||
out, err := gateway_iam.ListUsers(testAccountID, &iam.ListUsersInput{Marker: marker, MaxItems: aws.Int64(maxItems)}, svc)
|
||||
require.NoError(t, err)
|
||||
return out
|
||||
}
|
||||
@@ -78,7 +82,7 @@ func TestListUsers_DefaultPageIs100(t *testing.T) {
|
||||
svc.users = append(svc.users, fmt.Sprintf("user%03d", i))
|
||||
}
|
||||
|
||||
out, err := ListUsers(testAccountID, &iam.ListUsersInput{}, svc)
|
||||
out, err := gateway_iam.ListUsers(testAccountID, &iam.ListUsersInput{}, svc)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, out.Users, 100)
|
||||
assert.True(t, aws.BoolValue(out.IsTruncated))
|
||||
@@ -120,7 +124,7 @@ func TestListUsers_RejectsBadPagingBeforeListing(t *testing.T) {
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
svc := &listStub{users: []string{"a"}}
|
||||
_, err := ListUsers(testAccountID, tc.input, svc)
|
||||
_, err := gateway_iam.ListUsers(testAccountID, tc.input, svc)
|
||||
require.Error(t, err)
|
||||
assert.True(t, awserrors.IsErrorCode(err, awserrors.ErrorValidationError), "got %v", err)
|
||||
assert.Zero(t, svc.calls)
|
||||
@@ -144,12 +148,12 @@ func TestListPolicyVersions_PagesNewestFirst(t *testing.T) {
|
||||
return got
|
||||
}
|
||||
|
||||
first, err := ListPolicyVersions(testAccountID, &iam.ListPolicyVersionsInput{PolicyArn: aws.String("arn"), MaxItems: aws.Int64(2)}, svc)
|
||||
first, err := gateway_iam.ListPolicyVersions(testAccountID, &iam.ListPolicyVersionsInput{PolicyArn: aws.String("arn"), MaxItems: aws.Int64(2)}, svc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"v10", "v9"}, ids(first))
|
||||
assert.True(t, aws.BoolValue(first.IsTruncated))
|
||||
|
||||
second, err := ListPolicyVersions(testAccountID, &iam.ListPolicyVersionsInput{PolicyArn: aws.String("arn"), MaxItems: aws.Int64(2), Marker: first.Marker}, svc)
|
||||
second, err := gateway_iam.ListPolicyVersions(testAccountID, &iam.ListPolicyVersionsInput{PolicyArn: aws.String("arn"), MaxItems: aws.Int64(2), Marker: first.Marker}, svc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"v2"}, ids(second))
|
||||
assert.False(t, aws.BoolValue(second.IsTruncated))
|
||||
@@ -167,7 +171,7 @@ func TestListEntitiesForPolicy_PagesAcrossAllThreeLists(t *testing.T) {
|
||||
}}
|
||||
input := &iam.ListEntitiesForPolicyInput{PolicyArn: aws.String("arn"), MaxItems: aws.Int64(2)}
|
||||
|
||||
first, err := ListEntitiesForPolicy(testAccountID, input, svc)
|
||||
first, err := gateway_iam.ListEntitiesForPolicy(testAccountID, input, svc)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, first.PolicyGroups, 1)
|
||||
require.Len(t, first.PolicyRoles, 1)
|
||||
@@ -177,7 +181,7 @@ func TestListEntitiesForPolicy_PagesAcrossAllThreeLists(t *testing.T) {
|
||||
assert.True(t, aws.BoolValue(first.IsTruncated))
|
||||
|
||||
input.Marker = first.Marker
|
||||
second, err := ListEntitiesForPolicy(testAccountID, input, svc)
|
||||
second, err := gateway_iam.ListEntitiesForPolicy(testAccountID, input, svc)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, second.PolicyGroups)
|
||||
require.Len(t, second.PolicyRoles, 1)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package gateway_iam
|
||||
package gateway_iam_test
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/iam"
|
||||
gateway_iam "github.com/mulgadc/spinifex/spinifex/gateway/iam"
|
||||
handlers_iam "github.com/mulgadc/spinifex/spinifex/handlers/iam"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -89,70 +90,70 @@ func TestPolicyDocumentsAreURLEncoded(t *testing.T) {
|
||||
call func() ([]*string, error)
|
||||
}{
|
||||
{"CreateRole", func() ([]*string, error) {
|
||||
out, err := CreateRole(testAccountID, &iam.CreateRoleInput{RoleName: name, AssumeRolePolicyDocument: aws.String(rawDoc)}, svc)
|
||||
out, err := gateway_iam.CreateRole(testAccountID, &iam.CreateRoleInput{RoleName: name, AssumeRolePolicyDocument: aws.String(rawDoc)}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return roleDocs(out.Role), nil
|
||||
}},
|
||||
{"GetRole", func() ([]*string, error) {
|
||||
out, err := GetRole(testAccountID, &iam.GetRoleInput{RoleName: name}, svc)
|
||||
out, err := gateway_iam.GetRole(testAccountID, &iam.GetRoleInput{RoleName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return roleDocs(out.Role), nil
|
||||
}},
|
||||
{"ListRoles", func() ([]*string, error) {
|
||||
out, err := ListRoles(testAccountID, &iam.ListRolesInput{}, svc)
|
||||
out, err := gateway_iam.ListRoles(testAccountID, &iam.ListRolesInput{}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return roleDocs(out.Roles...), nil
|
||||
}},
|
||||
{"GetRolePolicy", func() ([]*string, error) {
|
||||
out, err := GetRolePolicy(testAccountID, &iam.GetRolePolicyInput{RoleName: name, PolicyName: name}, svc)
|
||||
out, err := gateway_iam.GetRolePolicy(testAccountID, &iam.GetRolePolicyInput{RoleName: name, PolicyName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*string{out.PolicyDocument}, nil
|
||||
}},
|
||||
{"GetUserPolicy", func() ([]*string, error) {
|
||||
out, err := GetUserPolicy(testAccountID, &iam.GetUserPolicyInput{UserName: name, PolicyName: name}, svc)
|
||||
out, err := gateway_iam.GetUserPolicy(testAccountID, &iam.GetUserPolicyInput{UserName: name, PolicyName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*string{out.PolicyDocument}, nil
|
||||
}},
|
||||
{"GetGroupPolicy", func() ([]*string, error) {
|
||||
out, err := GetGroupPolicy(testAccountID, &iam.GetGroupPolicyInput{GroupName: name, PolicyName: name}, svc)
|
||||
out, err := gateway_iam.GetGroupPolicy(testAccountID, &iam.GetGroupPolicyInput{GroupName: name, PolicyName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*string{out.PolicyDocument}, nil
|
||||
}},
|
||||
{"GetPolicyVersion", func() ([]*string, error) {
|
||||
out, err := GetPolicyVersion(testAccountID, &iam.GetPolicyVersionInput{PolicyArn: name, VersionId: aws.String("v1")}, svc)
|
||||
out, err := gateway_iam.GetPolicyVersion(testAccountID, &iam.GetPolicyVersionInput{PolicyArn: name, VersionId: aws.String("v1")}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*string{out.PolicyVersion.Document}, nil
|
||||
}},
|
||||
{"GetInstanceProfile", func() ([]*string, error) {
|
||||
out, err := GetInstanceProfile(testAccountID, &iam.GetInstanceProfileInput{InstanceProfileName: name}, svc)
|
||||
out, err := gateway_iam.GetInstanceProfile(testAccountID, &iam.GetInstanceProfileInput{InstanceProfileName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profileDocs(out.InstanceProfile), nil
|
||||
}},
|
||||
{"ListInstanceProfiles", func() ([]*string, error) {
|
||||
out, err := ListInstanceProfiles(testAccountID, &iam.ListInstanceProfilesInput{}, svc)
|
||||
out, err := gateway_iam.ListInstanceProfiles(testAccountID, &iam.ListInstanceProfilesInput{}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profileDocs(out.InstanceProfiles...), nil
|
||||
}},
|
||||
{"ListInstanceProfilesForRole", func() ([]*string, error) {
|
||||
out, err := ListInstanceProfilesForRole(testAccountID, &iam.ListInstanceProfilesForRoleInput{RoleName: name}, svc)
|
||||
out, err := gateway_iam.ListInstanceProfilesForRole(testAccountID, &iam.ListInstanceProfilesForRoleInput{RoleName: name}, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user