Skip to content

Commit

Permalink
Stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
hweawer committed Jan 8, 2025
1 parent 532a99a commit 782bf6c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
6 changes: 6 additions & 0 deletions nginx/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ var _nameToDefaultTemplate = map[string]string{
const DefaultClientVerification = `
ssl_verify_client optional;
set $required_verified_client 1;
if ($scheme = http) {
set $required_verified_client 0;
}
if ($request_method ~ ^(GET|HEAD)$) {
set $required_verified_client 0;
}
if ($remote_addr = "127.0.0.1") {
set $required_verified_client 0;
}
Expand Down
9 changes: 3 additions & 6 deletions nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -61,7 +61,7 @@ type Config struct {

func (c *Config) applyDefaults() error {
if c.Binary == "" {
c.Binary = "/usr/sbin/nginx"
c.Binary = "/opt/homebrew/bin/nginx"
}
if c.StdoutLogPath == "" {
if c.LogDir == "" {
Expand Down Expand Up @@ -215,10 +215,7 @@ func Run(config Config, params map[string]interface{}, opts ...Option) error {
return fmt.Errorf("write src: %s", err)
}

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)
}
stdout := os.Stdout

args := []string{config.Binary, "-g", "daemon off;", "-c", conf}
if config.Root {
Expand Down
62 changes: 62 additions & 0 deletions nginx/nginx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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.
}
*/

0 comments on commit 782bf6c

Please sign in to comment.