Agent/Proxy: Formatting and test cases fix
This commit is contained in:
parent
f0af60612c
commit
0b50b84429
|
@ -427,7 +427,7 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (*
|
||||||
}
|
}
|
||||||
go s.Flood(nil, portFn, s.serfWAN)
|
go s.Flood(nil, portFn, s.serfWAN)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start enterprise specific functionality
|
// Start enterprise specific functionality
|
||||||
if err := s.startEnterprise(); err != nil {
|
if err := s.startEnterprise(); err != nil {
|
||||||
s.Shutdown()
|
s.Shutdown()
|
||||||
|
|
|
@ -432,7 +432,10 @@ func (m *Manager) newProxy(mp *local.ManagedProxy) (Proxy, error) {
|
||||||
if err := m.configureLogDir(id, &cmd); err != nil {
|
if err := m.configureLogDir(id, &cmd); err != nil {
|
||||||
return nil, fmt.Errorf("error configuring proxy logs: %s", err)
|
return nil, fmt.Errorf("error configuring proxy logs: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pass in the environmental variables for this proxy process
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
// Build the daemon structure
|
// Build the daemon structure
|
||||||
proxy.Command = &cmd
|
proxy.Command = &cmd
|
||||||
proxy.ProxyID = id
|
proxy.ProxyID = id
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -286,27 +285,24 @@ func TestEnvironproxy(t *testing.T) {
|
||||||
go m.Run()
|
go m.Run()
|
||||||
|
|
||||||
//Get the environmental variables from the OS
|
//Get the environmental variables from the OS
|
||||||
//envCheck := os.Environ()
|
var fileContent []byte
|
||||||
var fileContent Bytes
|
|
||||||
var err error
|
var err error
|
||||||
var data Bytes
|
var data []byte
|
||||||
envData := os.Environ()
|
envData := os.Environ()
|
||||||
sort.Strings(envData)
|
sort.Strings(envData)
|
||||||
for _, envVariable := range envData {
|
for _, envVariable := range envData {
|
||||||
data = append(data, envVariable...)
|
data = append(data, envVariable...)
|
||||||
data = append(data, "\n"...)
|
data = append(data, "\n"...)
|
||||||
}
|
}
|
||||||
// t.Log(data)
|
|
||||||
|
// Check if the file written to from the spawned process
|
||||||
|
// has the necessary environmental variable data
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
if fileContent, err = ioutil.ReadFile(path); err != nil {
|
if fileContent, err = ioutil.ReadFile(path); err != nil {
|
||||||
r.Fatalf("No file ya dummy")
|
r.Fatalf("No file ya dummy")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Logf("Len (data) : %d , Len (fileContent) : %d", len(data), len(fileContent))
|
|
||||||
t.Logf("Type (data) : %s Type (fileContent) : %s", reflect.TypeOf(data), reflect.TypeOf(fileContent))
|
|
||||||
// t.Logf("File content: \n %s", fileContent)
|
|
||||||
// t.Logf("Data content: \n %s", data)
|
|
||||||
require.Equal(fileContent, data)
|
require.Equal(fileContent, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,22 +19,6 @@ import (
|
||||||
// *log.Logger instance.
|
// *log.Logger instance.
|
||||||
var testLogger = log.New(os.Stderr, "logger: ", log.LstdFlags)
|
var testLogger = log.New(os.Stderr, "logger: ", log.LstdFlags)
|
||||||
|
|
||||||
//SOrting interface
|
|
||||||
type Bytes []byte
|
|
||||||
|
|
||||||
//Length method for our Byte interface
|
|
||||||
func (b Bytes) Len() int {
|
|
||||||
return len(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b Bytes) Swap(i, j int) {
|
|
||||||
b[i], b[j] = b[j], b[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b Bytes) Less(i, j int) bool {
|
|
||||||
return b[i] < b[j]
|
|
||||||
}
|
|
||||||
|
|
||||||
// testTempDir returns a temporary directory and a cleanup function.
|
// testTempDir returns a temporary directory and a cleanup function.
|
||||||
func testTempDir(t *testing.T) (string, func()) {
|
func testTempDir(t *testing.T) (string, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
@ -162,14 +146,17 @@ func TestHelperProcess(t *testing.T) {
|
||||||
signal.Notify(stop, os.Interrupt)
|
signal.Notify(stop, os.Interrupt)
|
||||||
defer signal.Stop(stop)
|
defer signal.Stop(stop)
|
||||||
|
|
||||||
//Write the environmental variables into the file
|
//Get the path for the file to be written to
|
||||||
path := args[0]
|
path := args[0]
|
||||||
var data Bytes
|
var data []byte
|
||||||
// sort.Sort(data)
|
|
||||||
|
//Get the environmental variables
|
||||||
envData := os.Environ()
|
envData := os.Environ()
|
||||||
|
|
||||||
|
//Sort the env data for easier comparison
|
||||||
sort.Strings(envData)
|
sort.Strings(envData)
|
||||||
for _, envVariable := range envData {
|
for _, envVariable := range envData {
|
||||||
if strings.Contains(envVariable, "CONNECT_PROXY") {
|
if strings.HasPrefix(envVariable, "CONSUL") || strings.HasPrefix(envVariable, "CONNECT") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data = append(data, envVariable...)
|
data = append(data, envVariable...)
|
||||||
|
@ -181,6 +168,7 @@ func TestHelperProcess(t *testing.T) {
|
||||||
|
|
||||||
// Clean up after we receive the signal to exit
|
// Clean up after we receive the signal to exit
|
||||||
defer os.Remove(path)
|
defer os.Remove(path)
|
||||||
|
|
||||||
<-stop
|
<-stop
|
||||||
|
|
||||||
case "output":
|
case "output":
|
||||||
|
|
Loading…
Reference in New Issue