Skip to content

Commit

Permalink
Add tests for tags with custom values (kubernetes#11686)
Browse files Browse the repository at this point in the history
* Add tests for tags with custom values

* Fix typo in comments
  • Loading branch information
MrErlison authored and rikatz committed Sep 29, 2024
1 parent 866d3c7 commit ac2a43e
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions internal/ingress/controller/template/crossplane/crossplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,60 @@ func TestCrossplaneTemplate(t *testing.T) {
require.NoError(t, err)
require.NoError(t, mimeFile.Close())

t.Run("it should be able to marshall and unmarshall the current configuration", func(t *testing.T) {
tplConfig := &config.TemplateConfig{
Cfg: config.NewDefault(),
}
tplConfig := &config.TemplateConfig{
Cfg: config.NewDefault(),
}
tpl := crossplane.NewTemplate()

t.Run("it should be able to marshall and unmarshall the default configuration", func(t *testing.T) {
tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate
tplConfig.Cfg.EnableBrotli = true

tpl := crossplane.NewTemplate()
tpl.SetMimeFile(mimeFile.Name())
content, err := tpl.Write(tplConfig)
require.NoError(t, err)

tmpFile, err := os.CreateTemp("", "")
require.NoError(t, err)
_, err = tmpFile.Write(content)
require.NoError(t, err)
require.NoError(t, tmpFile.Close())

_, err = ngx_crossplane.Parse(tmpFile.Name(), &options)
require.NoError(t, err)
})

t.Run("it should be able to marshall and unmarshall the specified configuration", func(t *testing.T) {
tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate

tplConfig.Cfg.UseProxyProtocol = true

tplConfig.Cfg.GRPCBufferSizeKb = 10 // default 0

tplConfig.Cfg.HTTP2MaxHeaderSize = "10" // default ""
tplConfig.Cfg.HTTP2MaxFieldSize = "10" // default ""
tplConfig.Cfg.HTTP2MaxRequests = 1 // default 0

tplConfig.Cfg.UseGzip = true // default false
tplConfig.Cfg.GzipDisable = "enable"

tplConfig.Cfg.ShowServerTokens = true // default false

tplConfig.Cfg.DisableAccessLog = false // TODO: test true
tplConfig.Cfg.DisableHTTPAccessLog = false
tplConfig.Cfg.EnableSyslog = true
tplConfig.Cfg.SyslogHost = "localhost"

// Example: openssl rand 80 | openssl enc -A -base64
tplConfig.Cfg.SSLSessionTicketKey = "lOj3+7Xe21K9GapKqqPIw/gCQm5S4C2lK8pVne6drEik0QqOQHAw1AaPSMdbAvXx2zZKKPCEG98+g3hzftmrfnePSIvokIIE+hHto3Kj1HQ="

tplConfig.Cfg.CustomHTTPErrors = []int{1024, 2048}

tplConfig.Cfg.AllowBackendServerHeader = true // default false
tplConfig.Cfg.BlockCIDRs = []string{"192.168.0.0/24", " 200.200.0.0/16 "} // default 0
tplConfig.Cfg.BlockUserAgents = []string{"someuseragent", " another/user-agent "} // default 0

tpl = crossplane.NewTemplate()
tpl.SetMimeFile(mimeFile.Name())
content, err := tpl.Write(tplConfig)
require.NoError(t, err)
Expand Down

0 comments on commit ac2a43e

Please sign in to comment.