-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic test for get inventory report
Signed-off-by: Bradley Jones <bradley.jones@anchore.com>
- Loading branch information
1 parent
a2391e1
commit 9f26c03
Showing
3 changed files
with
94 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package inventory | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
"github.com/aws/aws-sdk-go/service/ecs/ecsiface" | ||
) | ||
|
||
type mockECSClient struct { | ||
ecsiface.ECSAPI | ||
} | ||
|
||
func (m *mockECSClient) ListClusters(*ecs.ListClustersInput) (*ecs.ListClustersOutput, error) { | ||
return &ecs.ListClustersOutput{ | ||
ClusterArns: []*string{ | ||
aws.String("arn:aws:ecs:us-east-1:123456789012:cluster/cluster-1"), | ||
aws.String("arn:aws:ecs:us-east-1:123456789012:cluster/cluster-2"), | ||
}, | ||
}, nil | ||
} | ||
|
||
func (m *mockECSClient) ListTasks(*ecs.ListTasksInput) (*ecs.ListTasksOutput, error) { | ||
return &ecs.ListTasksOutput{ | ||
TaskArns: []*string{ | ||
aws.String("arn:aws:ecs:us-east-1:123456789012:task/cluster-1/12345678-1234-1234-1234-000000000000"), | ||
aws.String("arn:aws:ecs:us-east-1:123456789012:task/cluster-1/12345678-1234-1234-1234-111111111111"), | ||
}, | ||
}, nil | ||
} | ||
|
||
func (m *mockECSClient) DescribeTasks(*ecs.DescribeTasksInput) (*ecs.DescribeTasksOutput, error) { | ||
return &ecs.DescribeTasksOutput{ | ||
Tasks: []*ecs.Task{ | ||
{ | ||
TaskArn: aws.String("arn:aws:ecs:us-east-1:123456789012:task/cluster-1/12345678-1234-1234-1234-000000000000"), | ||
Containers: []*ecs.Container{ | ||
{ | ||
Name: aws.String("container-1"), | ||
Image: aws.String("image-1"), | ||
ImageDigest: aws.String("sha256:1234567890123456789012345678901234567890123456789012345678901111"), | ||
}, | ||
{ | ||
Name: aws.String("container-2"), | ||
Image: aws.String("image-2"), | ||
ImageDigest: aws.String("sha256:1234567890123456789012345678901234567890123456789012345678902222"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
TaskArn: aws.String("arn:aws:ecs:us-east-1:123456789012:task/cluster-1/12345678-1234-1234-1234-111111111111"), | ||
Containers: []*ecs.Container{ | ||
{ | ||
Name: aws.String("container-3"), | ||
Image: aws.String("image-3"), | ||
ImageDigest: aws.String("sha256:1234567890123456789012345678901234567890123456789012345678903333"), | ||
}, | ||
{ | ||
Name: aws.String("container-4-(same-image-as-3)"), | ||
Image: aws.String("image-3"), | ||
ImageDigest: aws.String("sha256:1234567890123456789012345678901234567890123456789012345678903333"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package inventory | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/anchore/anchore-ecs-inventory/internal/logger" | ||
) | ||
|
||
func setupLogger() { | ||
// TODO(bradjones) Setting up logging for tests like this isn't great so will change this later | ||
logConfig := logger.LogConfig{ | ||
Level: "debug", | ||
} | ||
logger.InitLogger(logConfig) | ||
} | ||
|
||
func TestGetInventoryReportForCluster(t *testing.T) { | ||
setupLogger() | ||
|
||
mockSvc := &mockECSClient{} | ||
|
||
report, err := GetInventoryReportForCluster("cluster-1", mockSvc) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, 3, len(report.Results[0].Images)) | ||
} |