Skip to content

Commit

Permalink
chore: better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Feb 20, 2025
1 parent 13bb846 commit 21cb9bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 29 additions & 1 deletion plugin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions plugin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 21cb9bb

Please sign in to comment.