Files
akvorado/orchestrator/kafka/config_test.go
rastsislau-matusevich f2dfe55d27
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
orchestrator: add manage-topic flag and document skip-migrations (#2109)
2025-11-20 22:58:41 +01:00

96 lines
2.7 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package kafka
import (
"testing"
"akvorado/common/helpers"
"akvorado/common/reporter"
"akvorado/common/schema"
)
func TestDefaultConfiguration(t *testing.T) {
config := DefaultConfiguration()
if err := helpers.Validate.Struct(config); err != nil {
t.Fatalf("validate.Struct() error:\n%+v", err)
}
if !config.ManageTopic {
t.Error("ManageTopic should be true by default")
}
}
func TestManageTopicDisabled(t *testing.T) {
config := DefaultConfiguration()
config.ManageTopic = false
c, err := New(reporter.NewMock(t), config, Dependencies{Schema: schema.NewMock(t)})
if err != nil {
t.Fatalf("New() error:\n%+v", err)
}
if c != nil {
t.Error("Component should be nil when ManageTopic is false")
}
helpers.StartStop(t, c)
}
func TestShouldAlterConfiguration(t *testing.T) {
referenceTestFoo := "foo"
referenceTestBar := "bar"
referenceTestOtherFoo := "foo"
cases := []struct {
name string
target map[string]*string
source map[string]*string
strictPolicy bool
expected bool
}{
{
"subset in strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"a": &referenceTestFoo, "otherconfigentry": &referenceTestBar},
true, true,
}, {
"subset in non-strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"a": &referenceTestFoo, "otherconfigentry": &referenceTestBar},
false, false,
}, {
"subset with different references in non strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"a": &referenceTestOtherFoo, "otherconfigentry": &referenceTestBar},
false, false,
}, {
"missing config entry in strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"otherconfigentry": &referenceTestBar},
true, true,
}, {
"missing config entry in non-strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"otherconfigentry": &referenceTestBar},
false, true,
}, {
"same config in strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"a": &referenceTestOtherFoo},
true, false,
}, {
"same config in non-strict policy",
map[string]*string{"a": &referenceTestFoo},
map[string]*string{"a": &referenceTestOtherFoo},
false, false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := ShouldAlterConfiguration(tc.target, tc.source, tc.strictPolicy)
if got && !tc.expected {
t.Errorf("Configuration should not update inplace config.")
} else if !got && tc.expected {
t.Errorf("Configuration should update inplace config.")
}
})
}
}