Skip to content

Commit

Permalink
filters: move annotate into own package (#3023)
Browse files Browse the repository at this point in the history
This avoids import cycle when GetAnnotations helper is imported from
subpackage of filters.

Followup on #3022

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov authored Apr 19, 2024
1 parent e852b14 commit 0ce11b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions filters/builtin/annotate.go → filters/annotate/annotate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package builtin
package annotate

import (
"fmt"
Expand All @@ -16,10 +16,10 @@ type (

const annotateStateBagKey = "filter." + filters.AnnotateName

// NewAnnotate is a filter to annotate a filter chain.
// New creates filters to annotate a filter chain.
// It stores its key and value arguments into the filter context.
// Use [GetAnnotations] to retrieve the annotations from the context.
func NewAnnotate() filters.Spec {
func New() filters.Spec {
return annotateSpec{}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package builtin_test
package annotate_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/filters/annotate"
"github.com/zalando/skipper/filters/filtertest"
)

func TestAnnotate(t *testing.T) {
spec := builtin.NewAnnotate()
spec := annotate.New()

for _, tc := range []struct {
name string
Expand Down Expand Up @@ -46,13 +46,13 @@ func TestAnnotate(t *testing.T) {
filter.Request(ctx)
}

assert.Equal(t, tc.expected, builtin.GetAnnotations(ctx))
assert.Equal(t, tc.expected, annotate.GetAnnotations(ctx))
})
}
}

func TestAnnotateArgs(t *testing.T) {
spec := builtin.NewAnnotate()
spec := annotate.New()

t.Run("valid", func(t *testing.T) {
for _, def := range []string{
Expand Down
3 changes: 2 additions & 1 deletion filters/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package builtin
import (
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/accesslog"
"github.com/zalando/skipper/filters/annotate"
"github.com/zalando/skipper/filters/auth"
"github.com/zalando/skipper/filters/circuit"
"github.com/zalando/skipper/filters/consistenthash"
Expand Down Expand Up @@ -117,7 +118,7 @@ func Filters() []filters.Spec {
return []filters.Spec{
NewBackendIsProxy(),
NewComment(),
NewAnnotate(),
annotate.New(),
NewRequestHeader(),
NewSetRequestHeader(),
NewAppendRequestHeader(),
Expand Down

0 comments on commit 0ce11b9

Please sign in to comment.