-
Notifications
You must be signed in to change notification settings - Fork 2.5k
WIP: mock maintnotif tests #3639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ndyakov
wants to merge
18
commits into
ndyakov/feature/CAE-1313-maint-cluster
Choose a base branch
from
ndyakov/CAE-1910-proxy-tests
base: ndyakov/feature/CAE-1313-maint-cluster
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f3e9126
lazy cluster topology reload
ndyakov 6ed2349
Merge branch 'ndyakov/feature/CAE-1313-maint-cluster' into ndyakov/CA…
ndyakov e9da546
fix discrepancies between options structs
ndyakov 644a1aa
Merge branch 'ndyakov/feature/CAE-1313-maint-cluster' into ndyakov/CA…
ndyakov fc05874
Update osscluster_lazy_reload_test.go
ndyakov f3bab0d
Update osscluster.go
ndyakov 60c6edc
wip fault with mock proxy
ndyakov 1902cbb
Merge branch 'ndyakov/feature/CAE-1313-maint-cluster' into ndyakov/CA…
ndyakov 853c7f2
Merge branch 'ndyakov/feature/CAE-1313-maint-cluster' into ndyakov/CA…
ndyakov 908d602
make lint happy
ndyakov aa1f970
fix linter issues
ndyakov e097b3e
faster tests with mocks
ndyakov ce7fb37
linter once again
ndyakov e390e2d
Merge branch 'ndyakov/feature/CAE-1313-maint-cluster' into ndyakov/CA…
ndyakov 3923484
add complex node test
ndyakov 7971f01
add ci e2e
ndyakov 8e4ea91
use correct redis container
ndyakov 7decf55
e2e fix
ndyakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Build stage | ||
| FROM golang:1.21-alpine AS builder | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| # Copy go mod files | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Build the proxy-fi-server binary | ||
| RUN cd maintnotifications/e2e/cmd/proxy-fi-server && \ | ||
| CGO_ENABLED=0 GOOS=linux go build -o /proxy-fi-server . | ||
|
|
||
| # Runtime stage | ||
| FROM alpine:latest | ||
|
|
||
| RUN apk --no-cache add ca-certificates | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy the binary from builder | ||
| COPY --from=builder /proxy-fi-server . | ||
|
|
||
| # Expose the fault injector API port | ||
| EXPOSE 5000 | ||
|
|
||
| # Run the server | ||
| ENTRYPOINT ["/app/proxy-fi-server"] | ||
ndyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CMD ["--listen", "0.0.0.0:5000", "--proxy-api-port", "3000"] | ||
ndyakov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
|
|
||
| e2e "github.com/redis/go-redis/v9/maintnotifications/e2e" | ||
| ) | ||
|
|
||
| func main() { | ||
| listenAddr := flag.String("listen", "0.0.0.0:5000", "Address to listen on for fault injector API") | ||
| proxyAPIURL := flag.String("proxy-api-url", "http://localhost:8100", "URL of the cae-resp-proxy API") | ||
| flag.Parse() | ||
|
|
||
| fmt.Printf("Starting Proxy Fault Injector Server...\n") | ||
| fmt.Printf(" Listen address: %s\n", *listenAddr) | ||
| fmt.Printf(" Proxy API URL: %s\n", *proxyAPIURL) | ||
|
|
||
| server := e2e.NewProxyFaultInjectorServerWithURL(*listenAddr, *proxyAPIURL) | ||
| if err := server.Start(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Failed to start server: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Printf("Proxy Fault Injector Server started successfully\n") | ||
| fmt.Printf("Fault Injector API available at http://%s\n", *listenAddr) | ||
|
|
||
| // Wait for interrupt signal | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) | ||
| <-sigChan | ||
|
|
||
| fmt.Println("\nShutting down...") | ||
| if err := server.Stop(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error during shutdown: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Println("Server stopped") | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestCreateTestFaultInjectorLogic_WithoutEnv verifies the auto-start logic | ||
| // when REDIS_ENDPOINTS_CONFIG_PATH is not set | ||
| func TestCreateTestFaultInjectorLogic_WithoutEnv(t *testing.T) { | ||
| // Save original environment | ||
| origConfigPath := os.Getenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| origFIURL := os.Getenv("FAULT_INJECTION_API_URL") | ||
|
|
||
| // Clear environment to simulate no setup | ||
| os.Unsetenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| os.Unsetenv("FAULT_INJECTION_API_URL") | ||
|
|
||
| // Restore environment after test | ||
| defer func() { | ||
| if origConfigPath != "" { | ||
| os.Setenv("REDIS_ENDPOINTS_CONFIG_PATH", origConfigPath) | ||
| } | ||
| if origFIURL != "" { | ||
| os.Setenv("FAULT_INJECTION_API_URL", origFIURL) | ||
| } | ||
| }() | ||
|
|
||
| // Test GetEnvConfig - should fail when REDIS_ENDPOINTS_CONFIG_PATH is not set | ||
| envConfig, err := GetEnvConfig() | ||
| if err == nil { | ||
| t.Fatal("Expected GetEnvConfig() to fail when REDIS_ENDPOINTS_CONFIG_PATH is not set") | ||
| } | ||
| if envConfig != nil { | ||
| t.Fatal("Expected envConfig to be nil when GetEnvConfig() fails") | ||
| } | ||
|
|
||
| t.Log("✅ GetEnvConfig() correctly fails when REDIS_ENDPOINTS_CONFIG_PATH is not set") | ||
| t.Log("✅ This means CreateTestFaultInjectorWithCleanup() will auto-start the proxy") | ||
| } | ||
|
|
||
| // TestCreateTestFaultInjectorLogic_WithEnv verifies the logic | ||
| // when REDIS_ENDPOINTS_CONFIG_PATH is set | ||
| func TestCreateTestFaultInjectorLogic_WithEnv(t *testing.T) { | ||
| // Create a temporary config file | ||
| tmpFile := "/tmp/test_endpoints.json" | ||
| content := `{ | ||
| "standalone": { | ||
| "endpoints": ["redis://localhost:6379"] | ||
| } | ||
| }` | ||
|
|
||
| if err := os.WriteFile(tmpFile, []byte(content), 0644); err != nil { | ||
| t.Fatalf("Failed to create temp file: %v", err) | ||
| } | ||
| defer os.Remove(tmpFile) | ||
|
|
||
| // Save original environment | ||
| origConfigPath := os.Getenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| origFIURL := os.Getenv("FAULT_INJECTION_API_URL") | ||
|
|
||
| // Set environment | ||
| os.Setenv("REDIS_ENDPOINTS_CONFIG_PATH", tmpFile) | ||
| os.Setenv("FAULT_INJECTION_API_URL", "http://test-fi:9999") | ||
|
|
||
| // Restore environment after test | ||
| defer func() { | ||
| if origConfigPath != "" { | ||
| os.Setenv("REDIS_ENDPOINTS_CONFIG_PATH", origConfigPath) | ||
| } else { | ||
| os.Unsetenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| } | ||
| if origFIURL != "" { | ||
| os.Setenv("FAULT_INJECTION_API_URL", origFIURL) | ||
| } else { | ||
| os.Unsetenv("FAULT_INJECTION_API_URL") | ||
| } | ||
| }() | ||
|
|
||
| // Test GetEnvConfig - should succeed when REDIS_ENDPOINTS_CONFIG_PATH is set | ||
| envConfig, err := GetEnvConfig() | ||
| if err != nil { | ||
| t.Fatalf("Expected GetEnvConfig() to succeed when REDIS_ENDPOINTS_CONFIG_PATH is set, got error: %v", err) | ||
| } | ||
| if envConfig == nil { | ||
| t.Fatal("Expected envConfig to be non-nil when GetEnvConfig() succeeds") | ||
| } | ||
|
|
||
| // Verify the fault injector URL is correct | ||
| if envConfig.FaultInjectorURL != "http://test-fi:9999" { | ||
| t.Errorf("Expected FaultInjectorURL to be 'http://test-fi:9999', got '%s'", envConfig.FaultInjectorURL) | ||
| } | ||
|
|
||
| t.Log("✅ GetEnvConfig() correctly succeeds when REDIS_ENDPOINTS_CONFIG_PATH is set") | ||
| t.Log("✅ This means CreateTestFaultInjectorWithCleanup() will use the real fault injector") | ||
| t.Logf("✅ Fault injector URL: %s", envConfig.FaultInjectorURL) | ||
| } | ||
|
|
||
| // TestCreateTestFaultInjectorLogic_DefaultFIURL verifies the default fault injector URL | ||
| func TestCreateTestFaultInjectorLogic_DefaultFIURL(t *testing.T) { | ||
| // Create a temporary config file | ||
| tmpFile := "/tmp/test_endpoints2.json" | ||
| content := `{ | ||
| "standalone": { | ||
| "endpoints": ["redis://localhost:6379"] | ||
| } | ||
| }` | ||
|
|
||
| if err := os.WriteFile(tmpFile, []byte(content), 0644); err != nil { | ||
| t.Fatalf("Failed to create temp file: %v", err) | ||
| } | ||
| defer os.Remove(tmpFile) | ||
|
|
||
| // Save original environment | ||
| origConfigPath := os.Getenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| origFIURL := os.Getenv("FAULT_INJECTION_API_URL") | ||
|
|
||
| // Set only config path, not fault injector URL | ||
| os.Setenv("REDIS_ENDPOINTS_CONFIG_PATH", tmpFile) | ||
| os.Unsetenv("FAULT_INJECTION_API_URL") | ||
|
|
||
| // Restore environment after test | ||
| defer func() { | ||
| if origConfigPath != "" { | ||
| os.Setenv("REDIS_ENDPOINTS_CONFIG_PATH", origConfigPath) | ||
| } else { | ||
| os.Unsetenv("REDIS_ENDPOINTS_CONFIG_PATH") | ||
| } | ||
| if origFIURL != "" { | ||
| os.Setenv("FAULT_INJECTION_API_URL", origFIURL) | ||
| } | ||
| }() | ||
|
|
||
| // Test GetEnvConfig - should succeed and use default FI URL | ||
| envConfig, err := GetEnvConfig() | ||
| if err != nil { | ||
| t.Fatalf("Expected GetEnvConfig() to succeed, got error: %v", err) | ||
| } | ||
|
|
||
| // Verify the default fault injector URL | ||
| if envConfig.FaultInjectorURL != "http://localhost:8080" { | ||
| t.Errorf("Expected default FaultInjectorURL to be 'http://localhost:8080', got '%s'", envConfig.FaultInjectorURL) | ||
| } | ||
|
|
||
| t.Log("✅ GetEnvConfig() uses default fault injector URL when FAULT_INJECTION_API_URL is not set") | ||
| t.Logf("✅ Default fault injector URL: %s", envConfig.FaultInjectorURL) | ||
| } | ||
|
|
||
| // TestFaultInjectorClientCreation verifies that FaultInjectorClient can be created | ||
| func TestFaultInjectorClientCreation(t *testing.T) { | ||
| // Test creating client with different URLs | ||
| testCases := []struct { | ||
| name string | ||
| url string | ||
| }{ | ||
| {"localhost", "http://localhost:5000"}, | ||
| {"with port", "http://test:9999"}, | ||
| {"with trailing slash", "http://test:9999/"}, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| client := NewFaultInjectorClient(tc.url) | ||
| if client == nil { | ||
| t.Fatal("Expected non-nil client") | ||
| } | ||
|
|
||
| // Verify the base URL (should have trailing slash removed) | ||
| expectedURL := tc.url | ||
| if expectedURL[len(expectedURL)-1] == '/' { | ||
| expectedURL = expectedURL[:len(expectedURL)-1] | ||
| } | ||
|
|
||
| if client.GetBaseURL() != expectedURL { | ||
| t.Errorf("Expected base URL '%s', got '%s'", expectedURL, client.GetBaseURL()) | ||
| } | ||
|
|
||
| t.Logf("✅ Client created successfully with URL: %s", client.GetBaseURL()) | ||
| }) | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.