Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
falcon-pioupiou committed Dec 22, 2023
1 parent ae72cb9 commit 316d865
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,58 @@ func TestMakeSensorEnvMap(t *testing.T) {
t.Errorf("MakeSensorEnvMap() = %v, want %v", got, sensorConfig)
}
}


func TestMakeSensorEnvMapWithAutomaticProxy(t *testing.T) {
falconNode := falconv1alpha1.FalconNodeSensor{}
falconSensor := falconNode.Spec.Falcon
sensorConfig := make(map[string]string)
pDisabled := false
cid := "test"

falconSensor.APD = &pDisabled
falconSensor.Billing = "test"
falconSensor.CID = &cid
falconSensor.PToken = "test"
falconSensor.Tags = []string{"test"}
falconSensor.Trace = "debug"

os.Setenv("HTTPS_PROXY", "https://test.proxy:666")
proxy := NewProxyInfo()

// Set proxy values from environment variables if they exist
if proxy.Host() != "" {
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(),"https://")
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(),"http://")
}
if proxy.Port() != "" {
sensorConfig["FALCONCTL_OPT_APP"] = proxy.Port()
}

// Set sensor values from CRD
if falconSensor.APD != nil {
sensorConfig["FALCONCTL_OPT_APD"] = strconv.FormatBool(*falconSensor.APD)
}
if falconSensor.APH != "" {
sensorConfig["FALCONCTL_OPT_APH"] = falconSensor.APH
}
if falconSensor.APP != nil {
sensorConfig["FALCONCTL_OPT_APP"] = strconv.Itoa(*falconSensor.APP)
}
if falconSensor.Billing != "" {
sensorConfig["FALCONCTL_OPT_BILLING"] = falconSensor.Billing
}
if falconSensor.PToken != "" {
sensorConfig["FALCONCTL_OPT_PROVISIONING_TOKEN"] = falconSensor.PToken
}
if len(falconSensor.Tags) > 0 {
sensorConfig["FALCONCTL_OPT_TAGS"] = strings.Join(falconSensor.Tags, ",")
}
if falconSensor.Trace != "" {
sensorConfig["FALCONCTL_OPT_TRACE"] = falconSensor.Trace
}

if got := MakeSensorEnvMap(falconSensor); !reflect.DeepEqual(got, sensorConfig) {
t.Errorf("MakeSensorEnvMap() = %v, want %v", got, sensorConfig)
}
}

0 comments on commit 316d865

Please sign in to comment.