74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
|
package etl_test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log"
|
||
|
"testing"
|
||
|
|
||
|
"gitea.urkob.com/urko/ess-etl-go/config"
|
||
|
"gitea.urkob.com/urko/ess-etl-go/internal/etl"
|
||
|
"gitea.urkob.com/urko/ess-etl-go/internal/request"
|
||
|
"gitea.urkob.com/urko/ess-etl-go/internal/xml_loader"
|
||
|
"gitea.urkob.com/urko/ess-etl-go/pkg/adapter/repository/mongodb/employee_wi"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"go.mongodb.org/mongo-driver/mongo"
|
||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||
|
)
|
||
|
|
||
|
func BenchmarkLoad(b *testing.B) {
|
||
|
cfg := config.NewConfig(".env")
|
||
|
ctx := context.Background()
|
||
|
|
||
|
dbOpts := options.Client()
|
||
|
dbOpts.ApplyURI(cfg.DbAddress)
|
||
|
|
||
|
client, err := mongo.NewClient(dbOpts)
|
||
|
require.NoError(b, err, "mongo.NewClient")
|
||
|
|
||
|
require.NoError(b, client.Connect(ctx), "client.Connect")
|
||
|
|
||
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.EmployeeWorkInformationCollection)
|
||
|
if err = employeeWICollection.Drop(ctx); err != nil {
|
||
|
log.Fatalln("employeeWICollection.Drop", err)
|
||
|
}
|
||
|
repo := employee_wi.NewRepo(employeeWICollection)
|
||
|
|
||
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
||
|
|
||
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
||
|
from, to := "2023-01-01", "2023-01-31"
|
||
|
e := etl.New(ewiLoader, *repo)
|
||
|
|
||
|
b.ResetTimer()
|
||
|
for i := 0; i < b.N; i++ {
|
||
|
require.NoError(b, e.FanOut(ctx, cfg.EmployeeIdList, from, to))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestLoad(t *testing.T) {
|
||
|
cfg := config.NewConfig(".env")
|
||
|
ctx := context.Background()
|
||
|
|
||
|
dbOpts := options.Client()
|
||
|
dbOpts.ApplyURI(cfg.DbAddress)
|
||
|
|
||
|
client, err := mongo.NewClient(dbOpts)
|
||
|
require.NoError(t, err, "mongo.NewClient")
|
||
|
|
||
|
require.NoError(t, client.Connect(ctx), "client.Connect")
|
||
|
|
||
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.EmployeeWorkInformationCollection)
|
||
|
if err = employeeWICollection.Drop(ctx); err != nil {
|
||
|
log.Fatalln("employeeWICollection.Drop", err)
|
||
|
}
|
||
|
repo := employee_wi.NewRepo(employeeWICollection)
|
||
|
|
||
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
||
|
|
||
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
||
|
from, to := "2023-01-01", "2023-01-31"
|
||
|
e := etl.New(ewiLoader, *repo)
|
||
|
|
||
|
require.NoError(t, e.FanOut(ctx, cfg.EmployeeIdList, from, to))
|
||
|
}
|