Skip to content
Merged
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
45 changes: 6 additions & 39 deletions pkg/monitor/sqsevent/sqs-monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestMonitor_EventBridgeSuccess(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(nil),
ASG: &h.MockedASG{},
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -192,7 +192,6 @@ func TestMonitor_EventBridgeTestNotification(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedFalse(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -233,7 +232,7 @@ func TestMonitor_AsgDirectToSqsSuccess(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(nil),
ASG: &h.MockedASG{},
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -279,7 +278,6 @@ func TestMonitor_AsgDirectToSqsTestNotification(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedFalse(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -323,7 +321,7 @@ func TestMonitor_DrainTasks(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(&asgMock),
ASG: asgMock,
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -368,7 +366,7 @@ func TestMonitor_DrainTasks_Delay(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(&asgMock),
ASG: asgMock,
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -417,7 +415,7 @@ func TestMonitor_DrainTasks_Errors(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(&asgMock),
ASG: asgMock,
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -470,7 +468,7 @@ func TestMonitor_DrainTasksASGFailure(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(&asgMock),
ASG: asgMock,
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -748,7 +746,6 @@ func TestMonitor_EC2NoDNSName(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -788,7 +785,6 @@ func TestMonitor_EC2NoDNSNameOnTerminatedInstance(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -826,7 +822,6 @@ func TestMonitor_SQSDeleteFailure(t *testing.T) {
SQS: sqsMock,
EC2: ec2Mock,
ManagedTag: "aws-node-termination-handler/managed",
ASG: mockIsManagedTrue(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -864,7 +859,6 @@ func TestMonitor_InstanceNotManaged(t *testing.T) {
sqsMonitor := sqsevent.SQSMonitor{
SQS: sqsMock,
EC2: ec2Mock,
ASG: mockIsManagedFalse(nil),
CheckIfManaged: true,
QueueURL: "https://test-queue",
InterruptionChan: drainChan,
Expand Down Expand Up @@ -920,30 +914,3 @@ func getSQSMessageFromEvent(event sqsevent.EventBridgeEvent) (sqs.Message, error
eventStr := string(eventBytes)
return sqs.Message{Body: &eventStr}, nil
}

func mockIsManagedTrue(asg *h.MockedASG) h.MockedASG {
if asg == nil {
asg = &h.MockedASG{}
}
asg.DescribeAutoScalingInstancesResp = autoscaling.DescribeAutoScalingInstancesOutput{
AutoScalingInstances: []*autoscaling.InstanceDetails{
{AutoScalingGroupName: aws.String("test-asg")},
},
}
asg.DescribeTagsPagesResp = autoscaling.DescribeTagsOutput{
Tags: []*autoscaling.TagDescription{
{Key: aws.String("aws-node-termination-handler/managed")},
},
}
return *asg
}

func mockIsManagedFalse(asg *h.MockedASG) h.MockedASG {
if asg == nil {
asg = &h.MockedASG{}
}
asg.DescribeAutoScalingInstancesResp = autoscaling.DescribeAutoScalingInstancesOutput{
AutoScalingInstances: []*autoscaling.InstanceDetails{},
}
return *asg
}