Skip to content

Commit

Permalink
Add env group to render.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Aug 6, 2024
1 parent cc84619 commit df42566
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
66 changes: 66 additions & 0 deletions backend/pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -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'")
}
1 change: 1 addition & 0 deletions frontend/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.13.1
5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"typescript": "^5.2.2",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"engines": {
"node": ">=20.13.1"
}
}
}
3 changes: 3 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
startCommand: ./main
healthCheckPath: /health
envVars:
- fromGroup: flamingo-armond
- key: GQL_COMPLEXITY
sync: false
- key: PG_HOST
Expand All @@ -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
Expand Down

0 comments on commit df42566

Please sign in to comment.