error-pages/internal/config/config_test.go

39 lines
991 B
Go
Raw Normal View History

2024-06-21 23:32:10 +00:00
package config_test
import (
"testing"
"github.com/stretchr/testify/assert"
"gh.tarampamp.am/error-pages/internal/config"
)
func TestNew(t *testing.T) {
t.Parallel()
t.Run("default config", func(t *testing.T) {
var cfg = config.New()
assert.NotEmpty(t, cfg.Formats.XML)
assert.NotEmpty(t, cfg.Formats.JSON)
assert.True(t, len(cfg.Codes) >= 19)
assert.True(t, len(cfg.Templates) >= 2)
2024-06-22 08:05:01 +00:00
assert.NotEmpty(t, cfg.TemplateName)
assert.True(t, cfg.Templates.Has(cfg.TemplateName))
assert.Equal(t, uint16(404), cfg.Default.CodeToRender)
assert.Equal(t, uint16(404), cfg.Default.HttpCode)
2024-06-21 23:32:10 +00:00
})
t.Run("changing cfg1 should not affect cfg2", func(t *testing.T) {
var cfg1, cfg2 = config.New(), config.New()
cfg1.Codes["400"] = config.CodeDescription{Message: "foo", Description: "bar"}
assert.NotEqual(t, cfg1.Codes["400"], cfg2.Codes["400"])
2024-06-22 08:05:01 +00:00
cfg1.ProxyHeaders = append(cfg1.ProxyHeaders, "foo")
assert.NotEqual(t, cfg1.ProxyHeaders, cfg2.ProxyHeaders)
2024-06-21 23:32:10 +00:00
})
}