mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 00:21:16 +00:00
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package plugins
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestModuleConfigGet(t *testing.T) {
|
|
strPtrEmpty := func(v string) *string { return &v }("")
|
|
m := ModuleConfig{
|
|
"test": map[string]*FieldCollection{
|
|
DefaultConfigName: FieldCollectionFromData(map[string]any{
|
|
"setindefault": DefaultConfigName,
|
|
"setinboth": DefaultConfigName,
|
|
}),
|
|
"test": FieldCollectionFromData(map[string]any{
|
|
"setinchannel": "channel",
|
|
"setinboth": "channel",
|
|
}),
|
|
},
|
|
}
|
|
|
|
fields := m.GetChannelConfig("module_does_not_exist", "test")
|
|
require.NotNil(t, fields, "must always return a valid FieldCollection")
|
|
assert.Len(t, fields.Data(), 0)
|
|
|
|
fields = m.GetChannelConfig("test", "test")
|
|
assert.Equal(t, DefaultConfigName, fields.MustString("setindefault", strPtrEmpty))
|
|
assert.Equal(t, "channel", fields.MustString("setinchannel", strPtrEmpty))
|
|
assert.Equal(t, "channel", fields.MustString("setinboth", strPtrEmpty))
|
|
|
|
fields = m.GetChannelConfig("test", "channel_not_configured")
|
|
assert.Equal(t, DefaultConfigName, fields.MustString("setindefault", strPtrEmpty))
|
|
assert.Equal(t, "", fields.MustString("setinchannel", strPtrEmpty))
|
|
assert.Equal(t, DefaultConfigName, fields.MustString("setinboth", strPtrEmpty))
|
|
}
|