Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 2, 2023
1 parent 10554d7 commit 120de50
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/envoy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ func (p *Proxy) buildCommand(ctx context.Context, cfgPath string) *exec.Cmd {
// removeArgAndGetValue Function to get new args after removing given key
// and also returns the value of key
func removeArgAndGetValue(stringAr []string, key string) ([]string, string) {
for index, value := range stringAr {
if value == key {
return append(stringAr[:index], stringAr[index+2:]...), stringAr[index+1]
for index, item := range stringAr {
if item == key {
valueToReturn := stringAr[index+1]
return append(stringAr[:index], stringAr[index+2:]...), valueToReturn
}
}
return stringAr, ""
Expand Down
63 changes: 63 additions & 0 deletions pkg/envoy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,66 @@ func TestProxy_OverridingLoggerAndExtraArgs(t *testing.T) {
return p.cmd.Process.Signal(syscall.Signal(0)) == os.ErrProcessDone
}, 2*time.Second, 50*time.Millisecond)
}

func TestProxy_EnvoyExtraArgs(t *testing.T) {

This comment has been minimized.

Copy link
@curtbushko

curtbushko Jun 7, 2023

Contributor

These tests fail for me with failed to unmarshal output file: invalid character '\r' in string literal. Do they run for you?

(They are not being run in CI for some reason...)

bootstrapConfig := []byte(`hello world`)

// Test checks we are starting proxy with only one argument of log-level
// When log-level is present in both ProxyConfig and ExtraArgs
// We override the log-level with that of ExtraArgs
outputPath := testOutputPath()
t.Cleanup(func() { _ = os.Remove(outputPath) })

p, err := NewProxy(ProxyConfig{
Logger: hclog.New(&hclog.LoggerOptions{Level: hclog.Warn, Output: io.Discard}),
EnvoyErrorStream: io.Discard,
EnvoyOutputStream: io.Discard,
ExecutablePath: "testdata/fake-envoy",
ExtraArgs: []string{"--test-output", outputPath, "--log-level", "debug", "--concurrency", "1"},
BootstrapConfig: bootstrapConfig,
})
require.NoError(t, err)
require.NoError(t, p.Run(context.Background()))
t.Cleanup(func() { _ = p.Stop() })

// Read the output written by fake-envoy. It might take a while, so poll the
// file for a couple of second
var output struct {
Args []byte
ConfigData []byte
}
require.Eventually(t, func() bool {
outputBytes, err := os.ReadFile(outputPath)
if err != nil {
t.Logf("failed to read output file: %v", err)
return false
}
if err := json.Unmarshal(outputBytes, &output); err != nil {
t.Logf("failed to unmarshal output file: %v", err)
return false
}
return true
}, 2*time.Second, 50*time.Millisecond)

// Check that fake-envoy was able to read the config from the pipe.
require.Equal(t, bootstrapConfig, output.ConfigData)

// Check that we're correctly configuring the log level.
require.Contains(t, string(output.Args), "--log-level debug")

// Check that we're removing the logger in Proxy config and overriding it with extra args
require.NotContains(t, string(output.Args), "--log-level warn")

// Check that we're disabling hot restarts.
require.Contains(t, string(output.Args), "--disable-hot-restart")

This comment has been minimized.

Copy link
@curtbushko

curtbushko Jun 7, 2023

Contributor

I don't think --disable-hot-restart is being set anywhere?


// Check the process is still running.
require.NoError(t, p.cmd.Process.Signal(syscall.Signal(0)))

// Ensure Stop kills and reaps the process.
require.NoError(t, p.Stop())

require.Eventually(t, func() bool {
return p.cmd.Process.Signal(syscall.Signal(0)) == os.ErrProcessDone
}, 2*time.Second, 50*time.Millisecond)
}

0 comments on commit 120de50

Please sign in to comment.