mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-27 02:22:42 +00:00
fix(lib): remove mentions of botPolicies.json in the tests
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
+1
-1
@@ -169,7 +169,7 @@ func httpClient(t *testing.T) *http.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadPolicies(t *testing.T) {
|
func TestLoadPolicies(t *testing.T) {
|
||||||
for _, fname := range []string{"botPolicies.json", "botPolicies.yaml"} {
|
for _, fname := range []string{"botPolicies.yaml"} {
|
||||||
t.Run(fname, func(t *testing.T) {
|
t.Run(fname, func(t *testing.T) {
|
||||||
fin, err := data.BotPolicies.Open(fname)
|
fin, err := data.BotPolicies.Open(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrUnknownCheckType = errors.New("config.Bot.Check: unknown check type")
|
||||||
|
)
|
||||||
|
|
||||||
|
type AllChecks struct {
|
||||||
|
All []Check `json:"all"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AnyChecks struct {
|
||||||
|
All []Check `json:"any"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Check struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Args json.RawMessage `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Check) Valid(ctx context.Context) error {
|
||||||
|
var errs []error
|
||||||
|
|
||||||
|
if len(c.Type) == 0 {
|
||||||
|
errs = append(errs, ErrNoStoreBackend)
|
||||||
|
}
|
||||||
|
|
||||||
|
fac, ok := checker.Get(c.Type)
|
||||||
|
switch ok {
|
||||||
|
case true:
|
||||||
|
if err := fac.Valid(ctx, c.Args); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
errs = append(errs, fmt.Errorf("%w: %q", ErrUnknownCheckType, c.Type))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errs) != 0 {
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -13,13 +13,13 @@ import (
|
|||||||
func TestDefaultPolicyMustParse(t *testing.T) {
|
func TestDefaultPolicyMustParse(t *testing.T) {
|
||||||
ctx := thothmock.WithMockThoth(t)
|
ctx := thothmock.WithMockThoth(t)
|
||||||
|
|
||||||
fin, err := data.BotPolicies.Open("botPolicies.json")
|
fin, err := data.BotPolicies.Open("botPolicies.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer fin.Close()
|
defer fin.Close()
|
||||||
|
|
||||||
if _, err := ParseConfig(ctx, fin, "botPolicies.json", anubis.DefaultDifficulty); err != nil {
|
if _, err := ParseConfig(ctx, fin, "botPolicies.yaml", anubis.DefaultDifficulty); err != nil {
|
||||||
t.Fatalf("can't parse config: %v", err)
|
t.Fatalf("can't parse config: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user