fix: bump golang to 1.25, remove integration tests

This commit is contained in:
Arnaud Delcasse
2026-03-03 00:02:19 +01:00
parent 1787a90909
commit a40a7e2712
4 changed files with 1 additions and 411 deletions

View File

@@ -3,7 +3,7 @@ stages:
- publish
variables:
GOLANG_VERSION: "1.24"
GOLANG_VERSION: "1.25"
default:
image: golang:${GOLANG_VERSION}

View File

@@ -1,118 +0,0 @@
package storage
import (
"testing"
"github.com/google/uuid"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
var cfg2 *viper.Viper
func init() {
cfg2 = viper.New()
cfg2.SetDefault("storage.db.mongodb.host", "localhost")
cfg2.SetDefault("storage.db.mongodb.port", "27017")
cfg2.SetDefault("storage.db.mongodb.user", "mongodb")
cfg2.SetDefault("storage.db.mongodb.db_name", "mobilityaccounts_tests")
cfg2.SetDefault("storage.db.mongodb.sslmode", "disable")
cfg2.SetDefault("storage.db.mongodb.collections.users", "users")
cfg2.SetConfigName("config") // Define values in config.yaml
cfg2.AddConfigPath(".")
cfg2.ReadInConfig()
}
func TestMongoDBStorage_CreateAndGetAccount(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
err = db.CreateAccount(account1)
require.NoError(t, err)
result, err := db.GetAccount(account1.ID)
require.NoError(t, err)
require.Equal(t, &account1, result)
}
func TestMongoDBStorage_CreateAndGetAccountNoAuth(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
err = db.CreateAccount(account3)
require.NoError(t, err)
result, err := db.GetAccount(account3.ID)
require.NoError(t, err)
require.Equal(t, &account3, result)
}
func TestMongoDBStorage_UpdateAccount(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
err = db.CreateAccount(account2)
require.NoError(t, err)
modified := account2
modified.Authentication.Local.Email = Ptr("modifiedtest@test.com")
modified.Data["key1"] = "modeifiedvalue"
modified.Data["addedkey"] = "addedvalue"
modified.Metadata["addedmetadatakey"] = "addedmetadatavalue"
err = db.UpdateAccount(modified)
require.NoError(t, err)
result, err := db.GetAccount(account2.ID)
require.NoError(t, err)
require.Equal(t, &modified, result)
}
func TestMongoDBStorage_LocalAuthentication(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
_, err = db.LocalAuthentication(account1.Namespace, account1.Authentication.Local.Username, nil, nil)
require.NoError(t, err)
_, err = db.LocalAuthentication(account1.Namespace, nil, account1.Authentication.Local.Email, nil)
require.NoError(t, err)
_, err = db.LocalAuthentication(account1.Namespace, nil, nil, account1.Authentication.Local.PhoneNumber)
require.NoError(t, err)
}
func TestMongoDBStorage_GetAccounts(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
accounts, err := db.GetAccounts([]string{account1.Namespace, account3.Namespace})
require.NoError(t, err)
for _, account := range accounts {
require.Contains(t, []string{account1.Namespace, account3.Namespace}, account.Namespace)
}
}
func TestMongoDBsqlStorage_GetAccountsByIds(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
accounts, err := db.GetAccountsByIds([]string{account2.ID, account3.ID})
require.NoError(t, err)
for _, account := range accounts {
require.Contains(t, []string{account2.ID, account3.ID}, account.ID)
}
}
func TestMongoDBStorage_CreateAlreadyExistingCredentials(t *testing.T) {
db, err := NewMongoDBStorage(cfg2)
require.NoError(t, err)
modified := account1
modified.ID = uuid.NewString() // Change the ID to make as if it was a new one
err = db.CreateAccount(modified)
require.Error(t, err)
}

View File

@@ -1,225 +0,0 @@
package storage
import (
"context"
"fmt"
"reflect"
"testing"
"github.com/google/uuid"
_ "github.com/lib/pq"
"github.com/spf13/viper"
)
var cfg *viper.Viper
func init() {
cfg = viper.New()
cfg.SetDefault("storage.db.psql.host", "localhost")
cfg.SetDefault("storage.db.psql.port", "5432")
cfg.SetDefault("storage.db.psql.user", "postgres")
cfg.SetDefault("storage.db.psql.password", "postgres")
cfg.SetDefault("storage.db.psql.dbname", "coopgo_platform")
cfg.SetDefault("storage.db.psql.sslmode", "disable")
cfg.SetDefault("storage.db.psql.schema", "mobilityaccounts")
cfg.SetDefault("storage.db.psql.tables.accounts", "accounts")
cfg.SetDefault("storage.db.psql.tables.accounts_auth_local", "accounts_auth_local")
cfg.SetConfigName("config") // Override default values in a config.yaml file within this directory
cfg.AddConfigPath(".")
cfg.ReadInConfig()
}
func TestPostgresqlStorage_Initialize(t *testing.T) {
storage, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("error creating new PostgreSQL storage: %v", err)
}
defer storage.DbConnection.Close()
err = storage.Migrate()
if err != nil {
t.Errorf("database migration issue: %v", err)
return
}
tx, err := storage.DbConnection.BeginTx(context.Background(), nil)
if err != nil {
t.Errorf("transaction issue: %v", err)
return
}
defer tx.Rollback()
_, err = tx.Exec(fmt.Sprintf("DELETE FROM %s;", storage.Tables["accounts_auth_local"]))
if err != nil {
t.Errorf("delete accounts table issue: %v", err)
return
}
_, err = tx.Exec(fmt.Sprintf("DELETE FROM %s;", storage.Tables["accounts"]))
if err != nil {
t.Errorf("delete accounts table issue: %v", err)
return
}
if err = tx.Commit(); err != nil {
t.Errorf("commit transaction issue: %v", err)
return
}
}
func TestPostgresqlStorage_CreateAndGetAccount(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
}
err = db.CreateAccount(account1)
if err != nil {
t.Errorf("Failed to create account : %s", err)
return
}
result, err := db.GetAccount(account1.ID)
if err != nil {
t.Errorf("Failed to get account : %s", err)
return
}
if !reflect.DeepEqual(&account1, result) {
t.Errorf("The received account is not the same as expected\nSaved Account : %v\nRetrieved Account : %v", &account1, result)
}
}
func TestPostgresqlStorage_CreateAndGetAccountNoAuth(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
}
err = db.CreateAccount(account3)
if err != nil {
t.Errorf("Failed to create account : %s", err)
return
}
result, err := db.GetAccount(account3.ID)
if err != nil {
t.Errorf("Failed to get account : %s", err)
return
}
if !reflect.DeepEqual(&account3, result) {
t.Errorf("The received account is not the same as expected\nSaved Account : %v\nRetrieved Account : %v", &account3, result)
}
}
func TestPostgresqlStorage_UpdateAccount(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
}
err = db.CreateAccount(account2)
if err != nil {
t.Errorf("Failed to create account : %s", err)
return
}
modified := account2
modified.Authentication.Local.Email = Ptr("modifiedtest@test.com")
modified.Data["key1"] = "modeifiedvalue"
modified.Data["addedkey"] = "addedvalue"
modified.Metadata["addedmetadatakey"] = "addedmetadatavalue"
err = db.UpdateAccount(modified)
if err != nil {
t.Errorf("failed updating account : %s", err)
}
result, err := db.GetAccount(account2.ID)
if err != nil {
t.Errorf("Failed to get account : %s", err)
return
}
if !reflect.DeepEqual(&modified, result) {
t.Errorf("The received account is not the same as expected\nSaved Account : %v\nRetrieved Account : %v", &modified, result)
}
}
func TestPostgresqlStorage_LocalAuthentication(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
}
_, err = db.LocalAuthentication(account1.Namespace, account1.Authentication.Local.Username, nil, nil)
if err != nil {
t.Errorf("Failed LocalAuthentication based on username and namespace : %s", err)
}
_, err = db.LocalAuthentication(account1.Namespace, nil, account1.Authentication.Local.Email, nil)
if err != nil {
t.Errorf("Failed LocalAuthentication based on email and namespace :\n Namespace: %s\n Email: %s\nError: %s", account1.Namespace, *account1.Authentication.Local.Email, err)
}
_, err = db.LocalAuthentication(account1.Namespace, nil, nil, account1.Authentication.Local.PhoneNumber)
if err != nil {
t.Errorf("Failed LocalAuthentication based on phone number and namespace :\n Namespace: %s\n Phone number: %s\nError: %s", account1.Namespace, *account1.Authentication.Local.PhoneNumber, err)
}
}
func TestPostgresqlStorage_GetAccounts(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
}
accounts, err := db.GetAccounts([]string{account1.Namespace, account3.Namespace})
if err != nil {
t.Errorf("Failed : %s", err)
return
}
for _, account := range accounts {
if account.Namespace != account1.Namespace && account.Namespace != account3.Namespace {
t.Errorf("This namespace was not requested : %s", account.Namespace)
}
}
}
func TestPostgresqlStorage_GetAccountsByIds(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
return
}
accounts, err := db.GetAccountsByIds([]string{account2.ID, account3.ID})
if err != nil {
t.Errorf("Failed to get account by ID : %s", err)
return
}
found2 := false
found3 := false
for _, account := range accounts {
if account.ID == account2.ID {
found2 = true
} else if account.ID == account3.ID {
found3 = true
} else {
t.Errorf("This id was not requested : %s", account.ID)
}
}
if !found2 {
t.Errorf("account id not found for account2 : %s", account2.ID)
}
if !found3 {
t.Errorf("account id not found for account3 : %s", account3.ID)
}
}
func TestPostgresqlStorage_CreateAlreadyExistingCredentials(t *testing.T) {
db, err := NewPostgresqlStorage(cfg)
if err != nil {
t.Errorf("failed to create new psql connection")
return
}
modified := account1
modified.ID = uuid.NewString() // Change the ID to make as if it was a new one
err = db.CreateAccount(modified)
if err == nil {
t.Errorf("account should not be created : unique index violated !")
return
}
}

View File

@@ -1,67 +0,0 @@
package storage
import "github.com/google/uuid"
var account1 = Account{
ID: uuid.NewString(),
Namespace: "namespace",
Authentication: AccountAuth{
Local: &LocalAuth{
Username: Ptr("test"),
Password: "hashedpassword",
Email: Ptr("test@test.com"),
EmailValidation: &Validation{
Validated: true,
ValidationCode: "",
},
PhoneNumber: Ptr("+3312345678"),
PhoneNumberValidation: &Validation{
Validated: true,
ValidationCode: "",
},
},
},
Data: map[string]any{
"key1": "value1",
"key2": "value2",
},
Metadata: map[string]any{
"key1": "value1",
"key2": "value2",
},
}
var account2 = Account{
ID: uuid.NewString(),
Namespace: "test",
Authentication: AccountAuth{
Local: &LocalAuth{
Username: Ptr("test2"),
Password: "hashedpassword",
},
},
Data: map[string]any{
"key1": "value3",
"key2": "value4",
},
Metadata: map[string]any{
"key1": "value5",
"key2": "value6",
},
}
var account3 = Account{
ID: uuid.NewString(),
Namespace: "other_namespace",
Authentication: AccountAuth{
Local: nil,
},
Data: map[string]any{
"key1": "value3",
"key2": "value4",
},
Metadata: map[string]any{
"key1": "value5",
"key2": "value6",
},
}