2023-01-05 12:45:09 +01:00
|
|
|
package pipeline
|
|
|
|
|
|
|
|
import (
|
2023-01-11 09:13:59 +01:00
|
|
|
"context"
|
2023-01-05 12:45:09 +01:00
|
|
|
"errors"
|
2023-01-11 09:13:59 +01:00
|
|
|
"os"
|
2023-01-05 12:45:09 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grassrootseconomics/cic-chain-events/internal/fetch"
|
|
|
|
"github.com/grassrootseconomics/cic-chain-events/internal/filter"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/zerodha/logf"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-01-11 09:13:59 +01:00
|
|
|
graphqlEndpoint = os.Getenv("TEST_GRAPHQL_ENDPOINT")
|
2023-01-05 12:45:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type itPipelineTest struct {
|
|
|
|
suite.Suite
|
|
|
|
errorPipeline *Pipeline
|
|
|
|
normalPipeline *Pipeline
|
|
|
|
earlyExitPipeline *Pipeline
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPipelineSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(itPipelineTest))
|
|
|
|
}
|
|
|
|
|
|
|
|
type errorFilter struct{}
|
|
|
|
|
|
|
|
func newErrorFilter() filter.Filter {
|
|
|
|
return &errorFilter{}
|
|
|
|
}
|
|
|
|
|
2023-01-11 09:42:00 +01:00
|
|
|
func (*errorFilter) Execute(_ context.Context, _ fetch.Transaction) (bool, error) {
|
2023-01-05 12:45:09 +01:00
|
|
|
return false, errors.New("crash")
|
|
|
|
}
|
|
|
|
|
|
|
|
type earlyExitFilter struct{}
|
|
|
|
|
|
|
|
func newEarlyExitFilter() filter.Filter {
|
|
|
|
return &earlyExitFilter{}
|
|
|
|
}
|
|
|
|
|
2023-01-11 09:42:00 +01:00
|
|
|
func (*earlyExitFilter) Execute(_ context.Context, _ fetch.Transaction) (bool, error) {
|
2023-01-05 12:45:09 +01:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) SetupSuite() {
|
|
|
|
logger := logf.New(
|
|
|
|
logf.Opts{
|
|
|
|
Level: logf.DebugLevel,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
fetcher := fetch.NewGraphqlFetcher(fetch.GraphqlOpts{
|
|
|
|
GraphqlEndpoint: graphqlEndpoint,
|
|
|
|
})
|
|
|
|
|
|
|
|
noopFilter := filter.NewNoopFilter(filter.NoopFilterOpts{
|
|
|
|
Logg: logger,
|
|
|
|
})
|
|
|
|
errFilter := newErrorFilter()
|
|
|
|
earlyFilter := newEarlyExitFilter()
|
|
|
|
|
|
|
|
s.errorPipeline = NewPipeline(PipelineOpts{
|
|
|
|
Filters: []filter.Filter{
|
|
|
|
noopFilter,
|
|
|
|
errFilter,
|
|
|
|
},
|
|
|
|
BlockFetcher: fetcher,
|
|
|
|
Logg: logger,
|
|
|
|
})
|
|
|
|
|
|
|
|
s.normalPipeline = NewPipeline(PipelineOpts{
|
|
|
|
Filters: []filter.Filter{
|
|
|
|
noopFilter,
|
|
|
|
},
|
|
|
|
BlockFetcher: fetcher,
|
|
|
|
Logg: logger,
|
|
|
|
})
|
|
|
|
|
|
|
|
s.earlyExitPipeline = NewPipeline(PipelineOpts{
|
|
|
|
Filters: []filter.Filter{
|
|
|
|
noopFilter,
|
|
|
|
earlyFilter,
|
|
|
|
errFilter,
|
|
|
|
},
|
|
|
|
BlockFetcher: fetcher,
|
|
|
|
Logg: logger,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Existing_Block_No_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.normalPipeline.Run(context.Background(), 14974600)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Non_Existing_Block_No_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.normalPipeline.Run(context.Background(), 14974600000)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Existing_Block_Early() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.earlyExitPipeline.Run(context.Background(), 14974600)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Existing_Block_With_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.errorPipeline.Run(context.Background(), 14974600)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Non_Existing_Block_With_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.errorPipeline.Run(context.Background(), 14974600000)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Non_Existing_Block_Early() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.earlyExitPipeline.Run(context.Background(), 14974600000)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Empty_Block_With_No_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.normalPipeline.Run(context.Background(), 15370320)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Empty_Block_With_Err() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.errorPipeline.Run(context.Background(), 15370320)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *itPipelineTest) Test_E2E_Pipeline_Run_On_Empty_Block_Early() {
|
2023-01-11 09:13:59 +01:00
|
|
|
err := s.earlyExitPipeline.Run(context.Background(), 15370320)
|
2023-01-05 12:45:09 +01:00
|
|
|
s.NoError(err)
|
|
|
|
}
|