Skip to content

Commit

Permalink
TEST/MEDIUM: add tests for structured sections operations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaticevic committed Jul 31, 2024
1 parent 06552f6 commit c62d3a1
Show file tree
Hide file tree
Showing 14 changed files with 2,517 additions and 108 deletions.
20 changes: 18 additions & 2 deletions test/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ global
tune.quic.retry-threshold 5
tune.quic.socket-owner connection
tune.quic.zero-copy-fwd-send on
tune.zlib.memlevel 54
tune.zlib.windowsize 55
tune.zlib.memlevel 8
tune.zlib.windowsize 10
tune.memory.hot-size 56
busy-polling
max-spread-checks 1ms
Expand Down Expand Up @@ -615,6 +615,7 @@ frontend test
errorloc303 404 http://www.myawesomesite.com/not_found
error-log-format %T\ %t\ Some\ Text
guid guid-example
declare capture request len 1
frontend test_2 from test_defaults
mode http
Expand Down Expand Up @@ -1072,3 +1073,18 @@ func prepareClient(path string) (c configuration.Configuration, err error) {
}
return c, nil
}

func getTestClient() (configuration.Configuration, string, error) {
f, err := os.CreateTemp("/tmp", "haproxy-test*.txt")
if err != nil {
return nil, "", err
}
if err = prepareTestFile(testConf, f.Name()); err != nil {
return nil, "", err
}
c, err := prepareClient(f.Name())
if err != nil {
return nil, "", err
}
return c, f.Name(), nil
}
16 changes: 14 additions & 2 deletions test/expected/structured.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@
"vars_reqres_max_size": 53,
"vars_sess_max_size": 54,
"vars_txn_max_size": 55,
"zlib_memlevel": 54,
"zlib_windowsize": 55
"zlib_memlevel": 8,
"zlib_windowsize": 10
},
"tune_ssl_default_dh_param": 45,
"uid": 1,
Expand Down Expand Up @@ -672,6 +672,18 @@
"type": "set-dst-port"
}
],
"http_response_rule_list": [
{
"expr": "123",
"type": "set-fc-mark"
},
{
"expr": "1",
"type": "set-fc-tos",
"cond": "if",
"cond_test": "TRUE"
}
],
"server_switching_rule_list": [
{
"cond": "if",
Expand Down
212 changes: 108 additions & 104 deletions test/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,111 +51,8 @@ func checkGlobal(t *testing.T, global *models.Global) {
}

func TestPutGlobal(t *testing.T) {
tOut := int64(3600)
n := "1/1"
v := "0"
a := "/var/run/haproxy.sock"
f := "/etc/foo.lua"
luaPrependPath := "/usr/share/haproxy-lua/?/init.lua"
enabled := "enabled"
g := &models.Global{
GlobalBase: models.GlobalBase{
Daemon: "enabled",
CPUMaps: []*models.CPUMap{
{
Process: &n,
CPUSet: &v,
},
},
RuntimeAPIs: []*models.RuntimeAPI{
{
Address: &a,
BindParams: models.BindParams{
Level: "admin",
},
},
},
Maxconn: 1000,
SslDefaultBindCiphers: "test",
SslDefaultBindOptions: "ssl-min-ver TLSv1.0 no-tls-tickets",
SslDefaultServerCurves: "secp384r1",
StatsTimeout: &tOut,
ExternalCheck: false,
LuaPrependPath: []*models.LuaPrependPath{
{
Path: &luaPrependPath,
Type: "cpath",
},
},
LuaLoads: []*models.LuaLoad{
{
File: &f,
},
},
LogSendHostname: &models.GlobalLogSendHostname{
Enabled: &enabled,
Param: "something",
},
TuneOptions: &models.GlobalTuneOptions{
DisableZeroCopyForwarding: true,
EventsMaxEventsAtOnce: 50,
H1ZeroCopyFwdRecv: "disabled",
H1ZeroCopyFwdSend: "disabled",
H2ZeroCopyFwdSend: "disabled",
LuaLogLoggers: "disabled",
LuaLogStderr: "disabled",
MaxChecksPerThread: misc.Int64P(20),
PeersMaxUpdatesAtOnce: 100,
PtZeroCopyForwarding: "disabled",
QuicFrontendConnTxBuffersLimit: nil,
QuicFrontendMaxIdleTimeout: misc.Int64P(5000),
QuicSocketOwner: "listener",
RcvbufBackend: misc.Int64P(8192),
RcvbufFrontend: misc.Int64P(4096),
SndbufBackend: misc.Int64P(1234),
SndbufFrontend: misc.Int64P(5678),
SslOcspUpdateMaxDelay: misc.Int64P(48),
SslOcspUpdateMinDelay: misc.Int64P(49),
StickCounters: misc.Int64P(50),
},
HttpclientResolversDisabled: "disabled",
HttpclientResolversPrefer: "ipv6",
HttpclientResolversID: "my2",
HttpclientRetries: 5,
HttpclientSslCaFile: "my_ca_file.ca",
HttpclientTimeoutConnect: misc.Int64P(5000),
HttpclientSslVerify: misc.StringP(""),
UID: 1234,
WurflOptions: &models.GlobalWurflOptions{},
DeviceAtlasOptions: &models.GlobalDeviceAtlasOptions{},
FiftyOneDegreesOptions: &models.GlobalFiftyOneDegreesOptions{},
StatsMaxconn: misc.Int64P(30),
Anonkey: misc.Int64P(40),
NumaCPUMapping: "disabled",
DefaultPath: &models.GlobalDefaultPath{
Type: "origin",
Path: "/some/other/path",
},
NoQuic: false,
ClusterSecret: "",
SslDefaultServerSigalgs: "ECDSA+SHA256",
SslDefaultServerClientSigalgs: "ECDSA+SHA256",
SslPropquery: "foo",
SslProvider: "my_provider",
SslProviderPath: "providers/",
Setcap: "none",
LimitedQuic: true,
ProfilingMemory: "enabled",
Harden: &models.GlobalHarden{
RejectPrivilegedPorts: &models.GlobalHardenRejectPrivilegedPorts{
Quic: "enabled",
},
},
ThreadHardLimit: misc.Int64P(100),
SslSecurityLevel: misc.Int64P(2),
HTTPErrCodes: []*models.HTTPCodes{{Value: misc.StringP("100-150 -123 +599")}},
OcspUpdate: &models.GlobalOcspUpdate{},
},
GlobalBase: getGlobalBase(),
}

err := clientTest.PushGlobalConfiguration(g, "", version)
Expand Down Expand Up @@ -199,3 +96,110 @@ func TestPutGlobal(t *testing.T) {
t.Error("Should have returned version conflict.")
}
}

func getGlobalBase() models.GlobalBase {
tOut := int64(3600)
n := "1/1"
v := "0"
a := "/var/run/haproxy.sock"
f := "/etc/foo.lua"
luaPrependPath := "/usr/share/haproxy-lua/?/init.lua"
enabled := "enabled"
return models.GlobalBase{
Daemon: "enabled",
CPUMaps: []*models.CPUMap{
{
Process: &n,
CPUSet: &v,
},
},
RuntimeAPIs: []*models.RuntimeAPI{
{
Address: &a,
BindParams: models.BindParams{
Level: "admin",
},
},
},
Maxconn: 1000,
SslDefaultBindCiphers: "test",
SslDefaultBindOptions: "ssl-min-ver TLSv1.0 no-tls-tickets",
SslDefaultServerCurves: "secp384r1",
StatsTimeout: &tOut,
ExternalCheck: false,
LuaPrependPath: []*models.LuaPrependPath{
{
Path: &luaPrependPath,
Type: "cpath",
},
},
LuaLoads: []*models.LuaLoad{
{
File: &f,
},
},
LogSendHostname: &models.GlobalLogSendHostname{
Enabled: &enabled,
Param: "something",
},
TuneOptions: &models.GlobalTuneOptions{
DisableZeroCopyForwarding: true,
EventsMaxEventsAtOnce: 50,
H1ZeroCopyFwdRecv: "disabled",
H1ZeroCopyFwdSend: "disabled",
H2ZeroCopyFwdSend: "disabled",
LuaLogLoggers: "disabled",
LuaLogStderr: "disabled",
MaxChecksPerThread: misc.Int64P(20),
PeersMaxUpdatesAtOnce: 100,
PtZeroCopyForwarding: "disabled",
QuicFrontendConnTxBuffersLimit: nil,
QuicFrontendMaxIdleTimeout: misc.Int64P(5000),
QuicSocketOwner: "listener",
RcvbufBackend: misc.Int64P(8192),
RcvbufFrontend: misc.Int64P(4096),
SndbufBackend: misc.Int64P(1234),
SndbufFrontend: misc.Int64P(5678),
SslOcspUpdateMaxDelay: misc.Int64P(48),
SslOcspUpdateMinDelay: misc.Int64P(49),
StickCounters: misc.Int64P(50),
},
HttpclientResolversDisabled: "disabled",
HttpclientResolversPrefer: "ipv6",
HttpclientResolversID: "my2",
HttpclientRetries: 5,
HttpclientSslCaFile: "my_ca_file.ca",
HttpclientTimeoutConnect: misc.Int64P(5000),
HttpclientSslVerify: misc.StringP(""),
UID: 1234,
WurflOptions: &models.GlobalWurflOptions{},
DeviceAtlasOptions: &models.GlobalDeviceAtlasOptions{},
FiftyOneDegreesOptions: &models.GlobalFiftyOneDegreesOptions{},
StatsMaxconn: misc.Int64P(30),
Anonkey: misc.Int64P(40),
NumaCPUMapping: "disabled",
DefaultPath: &models.GlobalDefaultPath{
Type: "origin",
Path: "/some/other/path",
},
NoQuic: false,
ClusterSecret: "",
SslDefaultServerSigalgs: "ECDSA+SHA256",
SslDefaultServerClientSigalgs: "ECDSA+SHA256",
SslPropquery: "foo",
SslProvider: "my_provider",
SslProviderPath: "providers/",
Setcap: "none",
LimitedQuic: true,
ProfilingMemory: "enabled",
Harden: &models.GlobalHarden{
RejectPrivilegedPorts: &models.GlobalHardenRejectPrivilegedPorts{
Quic: "enabled",
},
},
ThreadHardLimit: misc.Int64P(100),
SslSecurityLevel: misc.Int64P(2),
HTTPErrCodes: []*models.HTTPCodes{{Value: misc.StringP("100-150 -123 +599")}},
OcspUpdate: &models.GlobalOcspUpdate{},
}
}
Loading

0 comments on commit c62d3a1

Please sign in to comment.