-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackend_test.go
85 lines (77 loc) · 1.89 KB
/
backend_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"errors"
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
"github.com/google/uuid"
)
type mockDynamoDB struct {
dynamodbiface.DynamoDBAPI
tableExist bool
item map[string]*dynamodb.AttributeValue
}
func (m *mockDynamoDB) DescribeTable(*dynamodb.DescribeTableInput) (*dynamodb.DescribeTableOutput, error) {
if !m.tableExist {
return &dynamodb.DescribeTableOutput{}, awserr.New(dynamodb.ErrCodeResourceNotFoundException, "doesNotExist", errors.New(""))
}
return &dynamodb.DescribeTableOutput{}, nil
}
func (m *mockDynamoDB) PutItem(input *dynamodb.PutItemInput) (*dynamodb.PutItemOutput, error) {
m.item = input.Item
return nil, nil
}
func (m *mockDynamoDB) GetItem(input *dynamodb.GetItemInput) (*dynamodb.GetItemOutput, error) {
return &dynamodb.GetItemOutput{
Item: m.item,
}, nil
}
func TestDynamoGetStoredPipeline(t *testing.T) {
pipelineConfig := []byte(`
{
"eventFolder": "testdata/eventTypes",
"sources": {
"fileInput": {
"type": "File",
"file_config": {
"path": "testdata/pipelines/input/file.in"
}
}
},
"rules": {
"searchRule": {
"source": "fileInput",
"plugin": "testdata/rules/a.so"
}
},
"states": {},
"sinks": {}
}
`)
id := uuid.New()
idVal, _ := id.MarshalText()
p := pipeline{
ID: id,
Config: pipelineConfig,
}
backend := &dynamoDBBackend{
svc: &mockDynamoDB{
tableExist: true,
},
TableName: "go-fish",
Retries: 0,
}
err := backend.Store(&p)
if err != nil {
t.Fatalf("Error storing pipeline %s", err)
}
storedBackend, err := backend.Get(idVal)
if err != nil {
t.Fatalf("Error retrieving pipeline %s", err)
}
if !reflect.DeepEqual(storedBackend, pipelineConfig) {
t.Errorf("Expected config %s\nGot %s", pipelineConfig, storedBackend)
}
}