fix tests

add feature flag for Auth
This commit is contained in:
jay brown
2025-04-14 14:46:28 -07:00
parent 7f9618cb14
commit a50d935c33
4 changed files with 23 additions and 9 deletions
+12
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"queryorchestration/internal/serviceconfig/auth"
@@ -15,6 +16,17 @@ import (
// RegisterRoutes registers all authentication-related routes to the Echo engine
func RegisterRoutes(e *echo.Echo, config auth.ConfigProvider) {
// check the auth feature flag
enableAuth := os.Getenv("ENABLE_AUTH")
if enableAuth == "" || strings.ToLower(enableAuth) == "false" {
return // Do nothing if auth is not enabled
}
// Only proceed if ENABLE_AUTH is "true" or "auth"
if strings.ToLower(enableAuth) != "true" {
return
}
// Register the login route - the middleware will handle this
e.GET(config.GetAuthLoginPath(), func(c echo.Context) error {
// This is handled by the middleware
+4
View File
@@ -12,6 +12,10 @@ A reusable Go package for AWS Cognito authentication and authorization with Echo
- Default home page with authentication status
- Simple integration with Echo framework
## Feature flag for Auth
To enable all of these features for all endpoints you must set
`ENABLE_AUTH=true` in your environment.
## Installation
```bash
+6 -8
View File
@@ -322,19 +322,15 @@ func TestPrettyPrintDebugOnly(t *testing.T) {
cfg.PrettyPrintDebugOnly()
// Close writer and restore stdout
w.Close()
os.Stdout = oldStdout
// Read captured output
var buf bytes.Buffer
if _, err := io.Copy(&buf, r); err != nil {
t.Fatalf("failed to copy output: %v", err)
}
// And later in the same function:
buf.Reset()
if _, err := io.Copy(&buf, r); err != nil {
t.Fatalf("failed to copy output: %v", err)
}
output := buf.String()
// Verify output contains expected values
@@ -353,7 +349,9 @@ func TestPrettyPrintDebugOnly(t *testing.T) {
}
// Test with DEBUG=false
os.Unsetenv("DEBUG")
os.Setenv("DEBUG", "false")
// Capture stdout again
r, w, _ = os.Pipe()
os.Stdout = w
@@ -367,7 +365,7 @@ func TestPrettyPrintDebugOnly(t *testing.T) {
t.Fatalf("failed to copy output: %v", err)
}
if output != "" {
if buf.String() != "" {
t.Error("Expected no output when DEBUG=false")
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ vars:
PKG: "./pkg/..."
CMD: "./cmd/..."
# yamllint disable-line rule:line-length
EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go|internal/cognitoauth/auth.go|internal/cognitoauth/handler.go|internal/cognitoauth/jwks.go|internal/cognitoauth/middleware.go|internal/cognitoauth/models.go|internal/cognitoauth/token.go|internal/cognitoauth/utils.go|api/queryAPI/authHandlers.go"
EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go|internal/cognitoauth/auth.go|internal/cognitoauth/handler.go|internal/cognitoauth/jwks.go|internal/cognitoauth/middleware.go|internal/cognitoauth/models.go|internal/cognitoauth/token.go|internal/cognitoauth/utils.go|api/queryAPI/authHandlers.go|api/queryAPI/homehandler.go"
includes:
docker: