-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcheck_test.go
71 lines (59 loc) · 1.88 KB
/
check_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sqs
import (
"context"
"errors"
"testing"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
)
// SimpleMockSQSClient is a manual mock of the SQSAPI interface.
type SimpleMockSQSClient struct {
// Add fields to store mock outputs and any other state
GetQueueAttributesOutput *sqs.GetQueueAttributesOutput
GetQueueAttributesErr error
}
// GetQueueAttributes is the mock method that mimics the corresponding SQSAPI method.
func (m *SimpleMockSQSClient) GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) {
// Return the mocked response and error stored in the mock struct
return m.GetQueueAttributesOutput, m.GetQueueAttributesErr
}
func TestNew(t *testing.T) {
queueURL := "http://example.com/queue"
mockSQSClient := &SimpleMockSQSClient{
GetQueueAttributesOutput: &sqs.GetQueueAttributesOutput{
Attributes: map[string]string{
string(types.QueueAttributeNameQueueArn): "arn:aws:sqs:us-east-1:123456789012:queue1",
},
},
GetQueueAttributesErr: nil,
}
config := Config{
Client: mockSQSClient,
QueueUrl: &queueURL,
}
checker := New(config)
err := checker(context.Background())
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
}
func TestNewError(t *testing.T) {
queueURL := "http://example.com/queue"
mockSQSClient := &SimpleMockSQSClient{
GetQueueAttributesOutput: &sqs.GetQueueAttributesOutput{
Attributes: map[string]string{
string(types.QueueAttributeNameQueueArn): "arn:aws:sqs:us-east-1:123456789012:queue1",
},
},
GetQueueAttributesErr: errors.New("failed to get queue attributes"),
}
config := Config{
Client: mockSQSClient,
QueueUrl: &queueURL,
}
checker := New(config)
err := checker(context.Background())
if err == nil {
t.Errorf("Expected error, but got none")
}
}