mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
fix integration test to work, init integration tests
This commit is contained in:
@@ -24,7 +24,7 @@ func (srv *server) GetPersonByGoogleId(c *gin.Context, googleId string) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, res)
|
||||
c.JSON(http.StatusOK, res.(map[string]any)["person"])
|
||||
}
|
||||
|
||||
func (srv *server) CreatePersonByGoogleIdAndInviteCode(c *gin.Context, googleId string) {
|
||||
@@ -56,7 +56,7 @@ func (srv *server) CreatePersonByGoogleIdAndInviteCode(c *gin.Context, googleId
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, res)
|
||||
c.JSON(http.StatusOK, res.(map[string]any)["person"])
|
||||
}
|
||||
|
||||
func (srv *server) CreatePersonByGoogleId(c *gin.Context, googleId string) {
|
||||
@@ -82,5 +82,5 @@ func (srv *server) CreatePersonByGoogleId(c *gin.Context, googleId string) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, res)
|
||||
c.JSON(http.StatusOK, res.(map[string]any)["person"])
|
||||
}
|
||||
|
@@ -8,6 +8,11 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
databaseReconnectTimeout = 5 * time.Second
|
||||
databaseReconnectAttempts = 5
|
||||
)
|
||||
|
||||
func InitDatabase(logger *zap.Logger, dbURI, dbUser, dbPassword string) neo4j.DriverWithContext {
|
||||
driver, err := neo4j.NewDriverWithContext(dbURI, neo4j.BasicAuth(dbUser, dbPassword, ""))
|
||||
if err != nil {
|
||||
@@ -15,7 +20,7 @@ func InitDatabase(logger *zap.Logger, dbURI, dbUser, dbPassword string) neo4j.Dr
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
for attempt := 1; attempt <= 5; attempt++ {
|
||||
for attempt := 1; attempt <= databaseReconnectAttempts; attempt++ {
|
||||
err = driver.VerifyConnectivity(ctx)
|
||||
if err == nil {
|
||||
break
|
||||
@@ -27,7 +32,7 @@ func InitDatabase(logger *zap.Logger, dbURI, dbUser, dbPassword string) neo4j.Dr
|
||||
zap.String("dbURI", dbURI),
|
||||
zap.Int("attempt", attempt),
|
||||
)
|
||||
time.Sleep(time.Duration(attempt*5) * time.Second)
|
||||
time.Sleep(time.Duration(attempt) * databaseReconnectTimeout)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
// StructToMap recursively converts a struct to a map using JSON tags.
|
||||
// Nil pointers and unexported fields are excluded.
|
||||
func StructToMap(input interface{}) map[string]interface{} {
|
||||
result := make(map[string]interface{})
|
||||
func StructToMap(input any) map[string]any {
|
||||
result := make(map[string]any)
|
||||
value := reflect.ValueOf(input)
|
||||
|
||||
if value.Kind() == reflect.Ptr {
|
||||
@@ -22,7 +22,7 @@ func StructToMap(input interface{}) map[string]interface{} {
|
||||
|
||||
typ := value.Type()
|
||||
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
for i := range value.NumField() {
|
||||
field := typ.Field(i)
|
||||
fieldValue := value.Field(i)
|
||||
|
||||
@@ -89,7 +89,7 @@ func indexComma(tag string) int {
|
||||
}
|
||||
|
||||
// Checks if a value is one of the preserved types that shouldn't be expanded recursively
|
||||
func isPreservedType(v interface{}) bool {
|
||||
func isPreservedType(v any) bool {
|
||||
switch v.(type) {
|
||||
case dbtype.Point2D, *dbtype.Point2D,
|
||||
dbtype.Point3D, *dbtype.Point3D,
|
||||
|
@@ -13,12 +13,12 @@ type NestedStruct struct {
|
||||
}
|
||||
|
||||
type TestStruct struct {
|
||||
ExportedField string `json:"exported_field"`
|
||||
unexportedField string // Should be ignored
|
||||
IgnoredField string `json:"-"`
|
||||
ExportedField string `json:"exported_field"`
|
||||
IgnoredField string `json:"-"`
|
||||
unexportedField string
|
||||
PointerField *string `json:"pointer_field"`
|
||||
Nested NestedStruct `json:"nested"`
|
||||
NilPointer *string `json:"nil_pointer"`
|
||||
Nested NestedStruct `json:"nested"`
|
||||
}
|
||||
|
||||
func TestStructToMap(t *testing.T) {
|
||||
@@ -35,10 +35,10 @@ func TestStructToMap(t *testing.T) {
|
||||
NilPointer: nil,
|
||||
}
|
||||
|
||||
expected := map[string]interface{}{
|
||||
expected := map[string]any{
|
||||
"exported_field": "exported value",
|
||||
"pointer_field": "pointer value",
|
||||
"nested": map[string]interface{}{
|
||||
"nested": map[string]any{
|
||||
"nested_field": "nested value",
|
||||
},
|
||||
}
|
||||
@@ -70,23 +70,23 @@ func TestStructToMap_EmptyStruct(t *testing.T) {
|
||||
func TestIsPreservedType(t *testing.T) {
|
||||
// Test cases for preserved types
|
||||
tests := []struct {
|
||||
input any
|
||||
name string
|
||||
input interface{}
|
||||
expected bool
|
||||
}{
|
||||
{"Point2D", dbtype.Point2D{}, true},
|
||||
{"Pointer to Point2D", &dbtype.Point2D{}, true},
|
||||
{"Point3D", dbtype.Point3D{}, true},
|
||||
{"Pointer to Point3D", &dbtype.Point3D{}, true},
|
||||
{"Time", time.Time{}, true},
|
||||
{"LocalDateTime", dbtype.LocalDateTime{}, true},
|
||||
{"Date", dbtype.Date{}, true},
|
||||
{"Time", dbtype.Time{}, true},
|
||||
{"LocalTime", dbtype.LocalTime{}, true},
|
||||
{"Duration", dbtype.Duration{}, true},
|
||||
{"String", "not preserved", false},
|
||||
{"Integer", 123, false},
|
||||
{"Struct", struct{}{}, false},
|
||||
{dbtype.Point2D{}, "Point2D", true},
|
||||
{&dbtype.Point2D{}, "Pointer to Point2D", true},
|
||||
{dbtype.Point3D{}, "Point3D", true},
|
||||
{&dbtype.Point3D{}, "Pointer to Point3D", true},
|
||||
{time.Time{}, "Time", true},
|
||||
{dbtype.LocalDateTime{}, "LocalDateTime", true},
|
||||
{dbtype.Date{}, "Date", true},
|
||||
{dbtype.Time{}, "Time", true},
|
||||
{dbtype.LocalTime{}, "LocalTime", true},
|
||||
{dbtype.Duration{}, "Duration", true},
|
||||
{"not preserved", "String", false},
|
||||
{123, "Integer", false},
|
||||
{struct{}{}, "Struct", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Reference in New Issue
Block a user