chore: better tests
This commit is contained in:
parent
13bb84651c
commit
21cb9bb110
2 changed files with 34 additions and 1 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue