From 8971b8e079c73ae0fc5a0701e7582e32bc971d14 Mon Sep 17 00:00:00 2001 From: hweawer Date: Mon, 20 Jan 2025 11:48:49 +0100 Subject: [PATCH] Revert writing error logs to stdout --- nginx/nginx.go | 5 +++- nginx/nginx_test.go | 62 --------------------------------------------- 2 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 nginx/nginx_test.go diff --git a/nginx/nginx.go b/nginx/nginx.go index 87cf9c87..d4e11f6a 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -215,7 +215,10 @@ func Run(config Config, params map[string]interface{}, opts ...Option) error { return fmt.Errorf("write src: %s", err) } - stdout := os.Stdout + stdout, err := os.OpenFile(config.StdoutLogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("open stdout log: %s", err) + } args := []string{config.Binary, "-g", "daemon off;", "-c", conf} if config.Root { diff --git a/nginx/nginx_test.go b/nginx/nginx_test.go deleted file mode 100644 index a9c251ff..00000000 --- a/nginx/nginx_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package nginx - -/* -import ( - "github.com/stretchr/testify/assert" - "github.com/uber/kraken/utils/httputil" - "os" - "testing" -) - - -func TestRun(t *testing.T) { - // Setup mock configuration parameters. - params := map[string]interface{}{} - - // Setup Nginx config instance with minimal params for the test - config := Config{ - Name: "kraken-origin", // Configuration file name - CacheDir: "/tmp/nginx/cache", // Cache directory for Nginx - LogDir: "/tmp/nginx/logs", // Log directory for Nginx - } - - // Optional: Setup TLS configuration for testing SSL (if needed). - tlsConfig := httputil.TLSConfig{ - Server: httputil.X509Pair{ - Disabled: true, - }, - } - WithTLS(tlsConfig)(&config) - - // Ensure necessary directories exist. - err := os.MkdirAll(config.CacheDir, 0755) - assert.NoError(t, err) - err = os.MkdirAll(config.LogDir, 0755) - assert.NoError(t, err) - - // Run the Nginx configuration generation and startup process. - err = Run(config, params) - if err != nil { - t.Fatalf("Failed to run Nginx: %v", err) - } - - // Test that the expected config file is created. - configFilePath := "/tmp/nginx/test_nginx_config" - _, err = os.Stat(configFilePath) - assert.NoError(t, err, "Config file should be created") - - // Test log file creation (stdout, access log, and error log). - _, err = os.Stat(config.StdoutLogPath) - assert.NoError(t, err, "stdout log file should be created") - - _, err = os.Stat(config.AccessLogPath) - assert.NoError(t, err, "access log file should be created") - - _, err = os.Stat(config.ErrorLogPath) - assert.NoError(t, err, "error log file should be created") - - // Optionally test the Nginx process itself (mock or run actual Nginx). - // Here you'd check if Nginx starts correctly, but this could be difficult to test - // in a unit test without a running system. -} -*/