Skip to content

Commit

Permalink
chore: test Config
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Feb 24, 2024
1 parent 62e2688 commit d9c30af
Showing 1 changed file with 201 additions and 0 deletions.
201 changes: 201 additions & 0 deletions pkg/config/toml_config/toml_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package toml_config_test

import (
tomlConfig "main/pkg/config/toml_config"
"testing"

"github.com/stretchr/testify/require"
)

func TestTomlConfigNoChains(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{}
require.Error(t, config.Validate())
}

func TestTomlConfigInvalidTimezone(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{},
},
Timezone: "invalid",
}
require.Error(t, config.Validate())
}

func TestTomlConfigInvalidChain(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{},
},
Timezone: "Etc/UTC",
}
require.Error(t, config.Validate())
}

func TestTomlConfigInvalidReporter(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{
Name: "chain",
TendermintNodes: []string{"node"},
APINodes: []string{"node"},
Queries: []string{"event.key = 'value'"},
},
},
Reporters: tomlConfig.Reporters{
{},
},
Timezone: "Etc/UTC",
}
require.Error(t, config.Validate())
}

func TestTomlConfigInvalidSubscription(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{
Name: "chain",
TendermintNodes: []string{"node"},
APINodes: []string{"node"},
Queries: []string{"event.key = 'value'"},
},
},
Reporters: tomlConfig.Reporters{
{
Name: "test",
Type: "telegram",
TelegramConfig: &tomlConfig.TelegramConfig{
Chat: 1,
Token: "xxx:yyy",
Admins: []int64{123},
},
},
},
Subscriptions: tomlConfig.Subscriptions{
{},
},
Timezone: "Etc/UTC",
}
require.Error(t, config.Validate())
}

func TestTomlConfigChainSubscriptionChainNotFound(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{
Name: "chain",
TendermintNodes: []string{"node"},
APINodes: []string{"node"},
Queries: []string{"event.key = 'value'"},
},
},
Reporters: tomlConfig.Reporters{
{
Name: "test",
Type: "telegram",
TelegramConfig: &tomlConfig.TelegramConfig{
Chat: 1,
Token: "xxx:yyy",
Admins: []int64{123},
},
},
},
Subscriptions: tomlConfig.Subscriptions{
{
Name: "name",
Reporter: "reporter",
ChainSubscriptions: tomlConfig.ChainSubscriptions{
{Chain: "nonexistent"},
},
},
},
Timezone: "Etc/UTC",
}
require.Error(t, config.Validate())
}

func TestTomlConfigSubscriptionReporterNotFound(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{
Name: "chain",
TendermintNodes: []string{"node"},
APINodes: []string{"node"},
Queries: []string{"event.key = 'value'"},
},
},
Reporters: tomlConfig.Reporters{
{
Name: "test",
Type: "telegram",
TelegramConfig: &tomlConfig.TelegramConfig{
Chat: 1,
Token: "xxx:yyy",
Admins: []int64{123},
},
},
},
Subscriptions: tomlConfig.Subscriptions{
{
Name: "name",
Reporter: "nonexistent",
ChainSubscriptions: tomlConfig.ChainSubscriptions{
{Chain: "chain"},
},
},
},
Timezone: "Etc/UTC",
}
require.Error(t, config.Validate())
}

func TestTomlConfigValid(t *testing.T) {
t.Parallel()

config := tomlConfig.TomlConfig{
Chains: tomlConfig.Chains{
{
Name: "chain",
TendermintNodes: []string{"node"},
APINodes: []string{"node"},
Queries: []string{"event.key = 'value'"},
},
},
Reporters: tomlConfig.Reporters{
{
Name: "test",
Type: "telegram",
TelegramConfig: &tomlConfig.TelegramConfig{
Chat: 1,
Token: "xxx:yyy",
Admins: []int64{123},
},
},
},
Subscriptions: tomlConfig.Subscriptions{
{
Name: "name",
Reporter: "test",
ChainSubscriptions: tomlConfig.ChainSubscriptions{
{Chain: "chain"},
},
},
},
Timezone: "Etc/UTC",
}
require.NoError(t, config.Validate())
}

0 comments on commit d9c30af

Please sign in to comment.