From 12bf9e7aafb3c8cbd844942fcc0b3781e51b4c85 Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Wed, 13 Sep 2023 16:56:26 -0400 Subject: [PATCH] Add deprecated warning tests --- .../internal/integration/parameters_test.go | 94 +++++++++++++------ 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/services/horizon/internal/integration/parameters_test.go b/services/horizon/internal/integration/parameters_test.go index c5a990e73c..0958063ae4 100644 --- a/services/horizon/internal/integration/parameters_test.go +++ b/services/horizon/internal/integration/parameters_test.go @@ -450,40 +450,74 @@ func TestDisableTxSub(t *testing.T) { }) } -func TestDeprecatedOutputForIngestionFilteringFlag(t *testing.T) { - originalStderr := os.Stderr - r, w, _ := os.Pipe() - os.Stderr = w - stdLog.SetOutput(os.Stderr) +func TestDeprecatedOutputs(t *testing.T) { + t.Run("deprecated output for ingestion filtering", func(t *testing.T) { + originalStderr := os.Stderr + r, w, _ := os.Pipe() + os.Stderr = w + stdLog.SetOutput(os.Stderr) - testConfig := integration.GetTestConfig() - testConfig.HorizonIngestParameters = map[string]string{"exp-enable-ingestion-filtering": "false"} - test := integration.NewTest(t, *testConfig) - err := test.StartHorizon() - assert.NoError(t, err) - test.WaitForHorizon() + testConfig := integration.GetTestConfig() + testConfig.HorizonIngestParameters = map[string]string{"exp-enable-ingestion-filtering": "false"} + test := integration.NewTest(t, *testConfig) + err := test.StartHorizon() + assert.NoError(t, err) + test.WaitForHorizon() - // Use a wait group to wait for the goroutine to finish before proceeding - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() - if err := w.Close(); err != nil { - t.Errorf("Failed to close Stdout") - return - } - }() + // Use a wait group to wait for the goroutine to finish before proceeding + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + if err := w.Close(); err != nil { + t.Errorf("Failed to close Stdout") + return + } + }() + + outputBytes, _ := io.ReadAll(r) + wg.Wait() // Wait for the goroutine to finish before proceeding + _ = r.Close() + os.Stderr = originalStderr + + assert.Contains(t, string(outputBytes), "DEPRECATED - No ingestion filter rules are defined by default, which equates to "+ + "no filtering of historical data. If you have never added filter rules to this deployment, then nothing further needed. "+ + "If you have defined ingestion filter rules prior but disabled filtering overall by setting this flag disabled with "+ + "--exp-enable-ingestion-filtering=false, then you should now delete the filter rules using the Horizon Admin API to achieve "+ + "the same no-filtering result. Remove usage of this flag in all cases.") + }) + t.Run("deprecated output for command-line flags", func(t *testing.T) { + originalStderr := os.Stderr + r, w, _ := os.Pipe() + os.Stderr = w + stdLog.SetOutput(os.Stderr) + + testConfig := integration.GetTestConfig() + test := integration.NewTest(t, *testConfig) + err := test.StartHorizon() + assert.NoError(t, err) + test.WaitForHorizon() - outputBytes, _ := io.ReadAll(r) - wg.Wait() // Wait for the goroutine to finish before proceeding - _ = r.Close() - os.Stderr = originalStderr + // Use a wait group to wait for the goroutine to finish before proceeding + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + if err := w.Close(); err != nil { + t.Errorf("Failed to close Stdout") + return + } + }() + + outputBytes, _ := io.ReadAll(r) + wg.Wait() // Wait for the goroutine to finish before proceeding + _ = r.Close() + os.Stderr = originalStderr - assert.Contains(t, string(outputBytes), "DEPRECATED - No ingestion filter rules are defined by default, which equates to "+ - "no filtering of historical data. If you have never added filter rules to this deployment, then nothing further needed. "+ - "If you have defined ingestion filter rules prior but disabled filtering overall by setting this flag disabled with "+ - "--exp-enable-ingestion-filtering=false, then you should now delete the filter rules using the Horizon Admin API to achieve "+ - "the same no-filtering result. Remove usage of this flag in all cases.") + assert.Contains(t, string(outputBytes), "DEPRECATED - the use of command-line flags has been deprecated "+ + "in favor of environment variables. Please consult our Configuring section in the developer documentation on "+ + "how to use them - https://developers.stellar.org/docs/run-api-server/configuring") + }) } func TestHelpOutput(t *testing.T) {