chore: better tests

This commit is contained in:
andig 2025-02-20 21:11:00 +01:00
parent 13bb84651c
commit 21cb9bb110
2 changed files with 34 additions and 1 deletions

View file

@ -7,7 +7,35 @@ import (
"github.com/stretchr/testify/assert"
)
func TestConfig(t *testing.T) {
func TestRequiredConfig(t *testing.T) {
var c Config
_, err := c.BoolGetter(context.TODO())
assert.Error(t, err)
_, err = c.IntSetter(context.TODO(), "foo")
assert.Error(t, err)
c = Config{
Source: "http",
Other: map[string]any{"uri": "http://localhost"},
}
g, err := c.BoolGetter(context.TODO())
assert.NoError(t, err)
assert.NotNil(t, g)
s, err := c.IntSetter(context.TODO(), "foo")
assert.NoError(t, err)
assert.NotNil(t, s)
c = Config{Source: "foo"}
_, err = c.BoolGetter(context.TODO())
assert.Error(t, err)
}
func TestOptionalConfig(t *testing.T) {
var c *Config
g, err := c.BoolGetter(context.TODO())

View file

@ -2,6 +2,7 @@ package plugin
import (
"context"
"errors"
"fmt"
"io"
"net/http"
@ -60,6 +61,10 @@ func NewHTTPPluginFromConfig(ctx context.Context, other map[string]interface{})
return nil, err
}
if cc.URI == "" {
return nil, errors.New("missing uri")
}
log := contextLogger(ctx, util.NewLogger("http"))
p := NewHTTP(
log,