Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into merge-master-xdr-next
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jul 28, 2023
2 parents e2f59bf + 62bc09d commit 1179bac
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 102 deletions.
102 changes: 0 additions & 102 deletions services/horizon/internal/integration/command_line_args_test.go

This file was deleted.

93 changes: 93 additions & 0 deletions services/horizon/internal/integration/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
package integration

import (
"bytes"
"fmt"
"io"
"io/ioutil"
stdLog "log"
"os"
"os/exec"
"path"
"strings"
"sync"
"testing"

"github.com/spf13/cobra"

"github.com/stellar/go/services/horizon/internal/paths"
"github.com/stellar/go/services/horizon/internal/simplepath"

Expand Down Expand Up @@ -212,6 +219,92 @@ func TestDisablePathFinding(t *testing.T) {
})
}

func TestIngestionFilteringAlwaysDefaultingToTrue(t *testing.T) {
t.Run("ingestion filtering flag set to default value", func(t *testing.T) {
test := NewParameterTest(t, map[string]string{})
err := test.StartHorizon()
assert.NoError(t, err)
test.WaitForHorizon()
assert.Equal(t, test.HorizonIngest().Config().EnableIngestionFiltering, true)
test.Shutdown()
})
t.Run("ingestion filtering flag set to false", func(t *testing.T) {
test := NewParameterTest(t, map[string]string{"exp-enable-ingestion-filtering": "false"})
err := test.StartHorizon()
assert.NoError(t, err)
test.WaitForHorizon()
assert.Equal(t, test.HorizonIngest().Config().EnableIngestionFiltering, true)
test.Shutdown()
})
}

func TestDeprecatedOutputForIngestionFilteringFlag(t *testing.T) {
originalStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w
stdLog.SetOutput(os.Stderr)

test := NewParameterTest(t, map[string]string{"exp-enable-ingestion-filtering": "false"})
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
}
}()

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.")
}

func TestHelpOutputForNoIngestionFilteringFlag(t *testing.T) {
config, flags := horizon.Flags()

horizonCmd := &cobra.Command{
Use: "horizon",
Short: "Client-facing api server for the Stellar network",
SilenceErrors: true,
SilenceUsage: true,
Long: "Client-facing API server for the Stellar network.",
RunE: func(cmd *cobra.Command, args []string) error {
_, err := horizon.NewAppFromFlags(config, flags)
if err != nil {
return err
}
return nil
},
}

var writer io.Writer = &bytes.Buffer{}
horizonCmd.SetOutput(writer)

horizonCmd.SetArgs([]string{"-h"})
if err := flags.Init(horizonCmd); err != nil {
fmt.Println(err)
}
if err := horizonCmd.Execute(); err != nil {
fmt.Println(err)
}

output := writer.(*bytes.Buffer).String()
assert.NotContains(t, output, "--exp-enable-ingestion-filtering")
}

// Pattern taken from testify issue:
// https://github.com/stretchr/testify/issues/858#issuecomment-600491003
//
Expand Down

0 comments on commit 1179bac

Please sign in to comment.