-
Notifications
You must be signed in to change notification settings - Fork 3
/
s3_test.go
108 lines (77 loc) · 1.93 KB
/
s3_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"strconv"
"strings"
"testing"
)
func TestNewS3Client(t *testing.T) {
config, err := LoadDefaultAWSConfig()
if err != nil {
t.Errorf("failed to load default aws config: %v", err)
}
s3c, err := NewS3Service(config)
if err != nil {
t.Errorf("failed to create new s3 client: %v", err)
}
if s3c.Client == nil {
t.Errorf("s3 client is nil")
}
}
func TestS3Service_CreatePartition(t *testing.T) {
config := Config{
Chain: Ethereum,
Network: EthereumGoerli,
Start: 0,
End: 25_000_000,
BatchSize: 1_000_000,
Env: Dev,
}
awsconfig, err := LoadDefaultAWSConfig()
check(t, err)
s3c, err := NewS3Service(awsconfig)
check(t, err)
glues, err := NewGlueService(awsconfig)
check(t, err)
err = glues.Introspect(config.Env)
check(t, err)
err = s3c.CreatePartition(glues, config)
check(t, err)
}
func TestAlreadyConsumed(t *testing.T) {
awsconfig, err := LoadDefaultAWSConfig()
if err != nil {
t.Errorf("failed to load default aws config: %v", err)
}
s3c, err := NewS3Service(awsconfig)
if err != nil {
t.Errorf("failed to create new s3 client: %v", err)
}
objs, err := s3c.ListObjects("casimir-analytics-event-bucket-dev1", "ethereum/goerli")
if err != nil {
t.Errorf("failed to list objects: %v", err)
}
fmt.Printf("# of objects: %d\n", len(*objs))
consumed := make([]int, 0)
duplicates := make(map[int]bool)
for _, v := range *objs {
splitt := strings.Split(v, "/")
block := strings.Split(splitt[len(splitt)-1], "=")[1]
num, err := strconv.Atoi(strings.Split(block, ".")[0])
if err != nil {
t.Errorf("failed to convert string to int: %v", err)
continue
}
if duplicates[num] {
t.Fatalf("duplicate element found: %d\n", num)
}
duplicates[num] = true
consumed = append(consumed, num)
}
fmt.Printf("# of consumed: %d\n", len(consumed))
}
func check(t *testing.T, err error) {
if err != nil {
t.Errorf(err.Error())
}
}