github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/plugin/responsetransformer/setup_test.go (about)

     1  package responsetransformer
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hellofresh/janus/pkg/plugin"
     7  	"github.com/hellofresh/janus/pkg/proxy"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestResponseTransformerConfig(t *testing.T) {
    12  	var config Config
    13  	rawConfig := map[string]interface{}{
    14  		"add": map[string]interface{}{
    15  			"headers": map[string]string{
    16  				"NAME": "TEST",
    17  			},
    18  			"querystring": map[string]string{
    19  				"name": "test",
    20  			},
    21  		},
    22  	}
    23  
    24  	err := plugin.Decode(rawConfig, &config)
    25  	assert.NoError(t, err)
    26  
    27  	assert.IsType(t, map[string]string{}, config.Add.Headers)
    28  	assert.Contains(t, config.Add.Headers, "NAME")
    29  }
    30  
    31  func TestResponseTransformerPlugin(t *testing.T) {
    32  	rawConfig := map[string]interface{}{
    33  		"add": map[string]interface{}{
    34  			"headers": map[string]string{
    35  				"NAME": "TEST",
    36  			},
    37  		},
    38  	}
    39  
    40  	def := proxy.NewRouterDefinition(proxy.NewDefinition())
    41  	err := setupResponseTransformer(def, rawConfig)
    42  	assert.NoError(t, err)
    43  
    44  	assert.Len(t, def.Middleware(), 1)
    45  }