From b61aafc1d58dfdd0a934de9c74ff59168d43db59 Mon Sep 17 00:00:00 2001 From: agentmarketbot Date: Sun, 5 Jan 2025 20:44:21 +0000 Subject: [PATCH] agent bot commit --- .gitignore | 1 + result/server.js | 2 +- result/test_config.js | 31 +++++++++++++++++++++++++++++++ vote/app.py | 2 +- vote/test_config.py | 25 +++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 result/test_config.js create mode 100644 vote/test_config.py diff --git a/.gitignore b/.gitignore index 9a6f694990..4751da8244 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/ obj/ .vs/ node_modules/ +.aider* diff --git a/result/server.js b/result/server.js index 1c8593e7ee..86003f64e2 100644 --- a/result/server.js +++ b/result/server.js @@ -18,7 +18,7 @@ io.on('connection', function (socket) { }); var pool = new Pool({ - connectionString: 'postgres://postgres:postgres@db/postgres' + connectionString: `postgres://postgres:postgres@${process.env.POSTGRES_HOST || 'db'}/postgres` }); async.retry( diff --git a/result/test_config.js b/result/test_config.js new file mode 100644 index 0000000000..654e021ae9 --- /dev/null +++ b/result/test_config.js @@ -0,0 +1,31 @@ +const assert = require('assert'); + +describe('Database Configuration', () => { + let originalEnv; + + beforeEach(() => { + originalEnv = process.env.POSTGRES_HOST; + }); + + afterEach(() => { + process.env.POSTGRES_HOST = originalEnv; + }); + + it('should use POSTGRES_HOST environment variable when set', () => { + process.env.POSTGRES_HOST = 'custom-host'; + const { Pool } = require('pg'); + const pool = new Pool({ + connectionString: `postgres://postgres:postgres@${process.env.POSTGRES_HOST || 'db'}/postgres` + }); + assert.ok(pool.options.connectionString.includes('custom-host')); + }); + + it('should default to "db" when POSTGRES_HOST is not set', () => { + delete process.env.POSTGRES_HOST; + const { Pool } = require('pg'); + const pool = new Pool({ + connectionString: `postgres://postgres:postgres@${process.env.POSTGRES_HOST || 'db'}/postgres` + }); + assert.ok(pool.options.connectionString.includes('@db/')); + }); +}); diff --git a/vote/app.py b/vote/app.py index 596546612a..3899e0808b 100644 --- a/vote/app.py +++ b/vote/app.py @@ -18,7 +18,7 @@ def get_redis(): if not hasattr(g, 'redis'): - g.redis = Redis(host="redis", db=0, socket_timeout=5) + g.redis = Redis(host=os.getenv('REDIS_HOST', 'redis'), db=0, socket_timeout=5) return g.redis @app.route("/", methods=['POST','GET']) diff --git a/vote/test_config.py b/vote/test_config.py new file mode 100644 index 0000000000..9ac1c92abb --- /dev/null +++ b/vote/test_config.py @@ -0,0 +1,25 @@ +import os +import unittest +from app import get_redis +from flask import g + +class TestConfig(unittest.TestCase): + def test_redis_host_config(self): + # Clear any existing redis connection + if hasattr(g, 'redis'): + delattr(g, 'redis') + + # Test default value + os.environ.pop('REDIS_HOST', None) + redis_conn = get_redis() + self.assertEqual(redis_conn.connection_pool.connection_kwargs['host'], 'redis') + + # Test custom value + os.environ['REDIS_HOST'] = 'custom-redis' + if hasattr(g, 'redis'): + delattr(g, 'redis') + redis_conn = get_redis() + self.assertEqual(redis_conn.connection_pool.connection_kwargs['host'], 'custom-redis') + +if __name__ == '__main__': + unittest.main()