diff --git a/backend/pkg/config/config.go b/backend/pkg/config/config.go index 0986ef5..d70de84 100644 --- a/backend/pkg/config/config.go +++ b/backend/pkg/config/config.go @@ -8,19 +8,19 @@ import ( // Config structure holds all the configuration values type Config struct { // System Settings - Port int `env:"PORT" envDefault:"1323"` - GoEnv string `env:"GO_ENV" envDefault:"dev"` + Port int `env:"PORT,notEmpty" envDefault:"1323"` + GoEnv string `env:"GO_ENV,notEmpty" envDefault:"dev"` // GraphQL related configurations - GQLComplexity int `env:"GQL_COMPLEXITY" envDefault:"10"` + GQLComplexity int `env:"GQL_COMPLEXITY,notEmpty" envDefault:"10"` - // PostgreSQL configuration - PGHost string `env:"PG_HOST" envDefault:"localhost"` - PGUser string `env:"PG_USER" envDefault:"testuser"` - PGPassword string `env:"PG_PASSWORD" envDefault:"testpassword"` - PGDBName string `env:"PG_DBNAME" envDefault:"flamingodb"` - PGPort string `env:"PG_PORT" envDefault:"5432"` - PGSSLMode string `env:"PG_SSLMODE" envDefault:"allow"` + // PostgresSQL configuration + PGHost string `env:"PG_HOST,notEmpty" envDefault:"localhost"` + PGUser string `env:"PG_USER,notEmpty" envDefault:"testuser"` + PGPassword string `env:"PG_PASSWORD,notEmpty" envDefault:"testpassword"` + PGDBName string `env:"PG_DBNAME,notEmpty" envDefault:"flamingodb"` + PGPort string `env:"PG_PORT,notEmpty" envDefault:"5432"` + PGSSLMode string `env:"PG_SSLMODE,notEmpty" envDefault:"allow"` } // Cfg is the package-level variable that holds the parsed configuration diff --git a/backend/pkg/config/config_test.go b/backend/pkg/config/config_test.go new file mode 100644 index 0000000..d3b8c52 --- /dev/null +++ b/backend/pkg/config/config_test.go @@ -0,0 +1,66 @@ +package config_test + +import ( + "os" + "testing" + + "backend/pkg/config" + "github.com/caarlos0/env/v11" + "github.com/stretchr/testify/assert" +) + +func TestConfigDefaults(t *testing.T) { + // Explicitly set environment variables + os.Setenv("PORT", "") + os.Setenv("GO_ENV", "") + os.Setenv("GQL_COMPLEXITY", "") + os.Setenv("PG_HOST", "") + os.Setenv("PG_USER", "") + os.Setenv("PG_PASSWORD", "") + os.Setenv("PG_DBNAME", "") + os.Setenv("PG_PORT", "") + os.Setenv("PG_SSLMODE", "") + + // Parse environment variables + err := env.Parse(&config.Cfg) + assert.NoError(t, err, "Config should parse without error") + + // Verify default values + assert.Equal(t, 1323, config.Cfg.Port, "Default Port should be 1323") + assert.Equal(t, "dev", config.Cfg.GoEnv, "Default GoEnv should be 'dev'") + assert.Equal(t, 10, config.Cfg.GQLComplexity, "Default GQLComplexity should be 10") + assert.Equal(t, "localhost", config.Cfg.PGHost, "Default PGHost should be 'localhost'") + assert.Equal(t, "testuser", config.Cfg.PGUser, "Default PGUser should be 'testuser'") + assert.Equal(t, "testpassword", config.Cfg.PGPassword, "Default PGPassword should be 'testpassword'") + assert.Equal(t, "flamingodb", config.Cfg.PGDBName, "Default PGDBName should be 'flamingodb'") + assert.Equal(t, "5432", config.Cfg.PGPort, "Default PGPort should be '5432'") + assert.Equal(t, "allow", config.Cfg.PGSSLMode, "Default PGSSLMode should be 'allow'") +} + +func TestConfigCustomValues(t *testing.T) { + // Set environment variables to custom values + os.Setenv("PORT", "8080") + os.Setenv("GO_ENV", "production") + os.Setenv("GQL_COMPLEXITY", "20") + os.Setenv("PG_HOST", "customhost") + os.Setenv("PG_USER", "customuser") + os.Setenv("PG_PASSWORD", "custompassword") + os.Setenv("PG_DBNAME", "customdb") + os.Setenv("PG_PORT", "6543") + os.Setenv("PG_SSLMODE", "require") + + // Parse environment variables + err := env.Parse(&config.Cfg) + assert.NoError(t, err, "Config should parse without error") + + // Verify custom values + assert.Equal(t, 8080, config.Cfg.Port, "Port should be 8080") + assert.Equal(t, "production", config.Cfg.GoEnv, "GoEnv should be 'production'") + assert.Equal(t, 20, config.Cfg.GQLComplexity, "GQLComplexity should be 20") + assert.Equal(t, "customhost", config.Cfg.PGHost, "PGHost should be 'customhost'") + assert.Equal(t, "customuser", config.Cfg.PGUser, "PGUser should be 'customuser'") + assert.Equal(t, "custompassword", config.Cfg.PGPassword, "PGPassword should be 'custompassword'") + assert.Equal(t, "customdb", config.Cfg.PGDBName, "PGDBName should be 'customdb'") + assert.Equal(t, "6543", config.Cfg.PGPort, "PGPort should be '6543'") + assert.Equal(t, "require", config.Cfg.PGSSLMode, "PGSSLMode should be 'require'") +} diff --git a/frontend/.node-version b/frontend/.node-version new file mode 100644 index 0000000..297d47b --- /dev/null +++ b/frontend/.node-version @@ -0,0 +1 @@ +20.13.1 \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 24d4287..375a469 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -43,5 +43,8 @@ "typescript": "^5.2.2", "vite": "^5.3.1", "vitest": "^1.6.0" + }, + "engines": { + "node": ">=20.13.1" } -} +} \ No newline at end of file diff --git a/render.yaml b/render.yaml index bba9794..e0bcb8a 100644 --- a/render.yaml +++ b/render.yaml @@ -1,4 +1,4 @@ -version: 1 +version: "1" services: - type: web @@ -11,6 +11,7 @@ services: startCommand: ./main healthCheckPath: /health envVars: + - fromGroup: flamingo-armond - key: GQL_COMPLEXITY sync: false - key: PG_HOST @@ -33,6 +34,8 @@ services: rootDir: frontend buildCommand: npm install -g pnpm && pnpm install && pnpm run build staticPublishPath: frontend/build + envVars: + - fromGroup: flamingo-armond buildFilter: paths: - src/**/*.tsx