github.com/Jeffail/benthos/v3@v3.65.0/lib/test/integration/amqp_0_9_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/Jeffail/benthos/v3/internal/integration"
     9  	"github.com/ory/dockertest/v3"
    10  	amqp "github.com/rabbitmq/amqp091-go"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  var _ = registerIntegrationTest("amqp_0_9", func(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	pool, err := dockertest.NewPool("")
    19  	require.NoError(t, err)
    20  
    21  	pool.MaxWait = time.Second * 30
    22  
    23  	resource, err := pool.Run("rabbitmq", "latest", nil)
    24  	require.NoError(t, err)
    25  	t.Cleanup(func() {
    26  		assert.NoError(t, pool.Purge(resource))
    27  	})
    28  
    29  	resource.Expire(900)
    30  	require.NoError(t, pool.Retry(func() error {
    31  		client, err := amqp.Dial(fmt.Sprintf("amqp://guest:guest@localhost:%v/", resource.GetPort("5672/tcp")))
    32  		if err == nil {
    33  			client.Close()
    34  		}
    35  		return err
    36  	}))
    37  
    38  	template := `
    39  output:
    40    amqp_0_9:
    41      urls:
    42        - amqp://guest:guest@localhost:1234/
    43        - amqp://guest:guest@localhost:$PORT/ # fallback URL
    44        - amqp://guest:guest@localhost:4567/
    45      max_in_flight: $MAX_IN_FLIGHT
    46      exchange: exchange-$ID
    47      key: benthos-key
    48      exchange_declare:
    49        enabled: true
    50        type: direct
    51        durable: true
    52      metadata:
    53        exclude_prefixes: [ $OUTPUT_META_EXCLUDE_PREFIX ]
    54  
    55  input:
    56    amqp_0_9:
    57      urls:
    58        - amqp://guest:guest@localhost:1234/
    59        - amqp://guest:guest@localhost:$PORT/ # fallback URL
    60        - amqp://guest:guest@localhost:4567/
    61      auto_ack: $VAR1
    62      queue: queue-$ID
    63      queue_declare:
    64        durable: true
    65        enabled: true
    66      bindings_declare:
    67        - exchange: exchange-$ID
    68          key: benthos-key
    69  `
    70  
    71  	suite := integration.StreamTests(
    72  		integration.StreamTestOpenClose(),
    73  		integration.StreamTestMetadata(),
    74  		integration.StreamTestMetadataFilter(),
    75  		integration.StreamTestSendBatch(10),
    76  		integration.StreamTestStreamSequential(1000),
    77  		integration.StreamTestStreamParallel(1000),
    78  		integration.StreamTestStreamParallelLossy(1000),
    79  		integration.StreamTestStreamParallelLossyThroughReconnect(1000),
    80  	)
    81  	suite.Run(
    82  		t, template,
    83  		integration.StreamTestOptSleepAfterInput(500*time.Millisecond),
    84  		integration.StreamTestOptSleepAfterOutput(500*time.Millisecond),
    85  		integration.StreamTestOptPort(resource.GetPort("5672/tcp")),
    86  		integration.StreamTestOptVarOne("false"),
    87  	)
    88  
    89  	backwardsCompatibilityTemplate := `
    90  output:
    91    amqp_0_9:
    92      url: amqp://guest:guest@localhost:$PORT/
    93      max_in_flight: $MAX_IN_FLIGHT
    94      exchange: exchange-$ID
    95      key: benthos-key
    96      exchange_declare:
    97        enabled: true
    98        type: direct
    99        durable: true
   100      metadata:
   101        exclude_prefixes: [ $OUTPUT_META_EXCLUDE_PREFIX ]
   102  
   103  input:
   104    amqp_0_9:
   105      url: amqp://guest:guest@localhost:$PORT/
   106      auto_ack: $VAR1
   107      queue: queue-$ID
   108      queue_declare:
   109        durable: true
   110        enabled: true
   111      bindings_declare:
   112        - exchange: exchange-$ID
   113          key: benthos-key
   114  `
   115  
   116  	suite.Run(
   117  		t, backwardsCompatibilityTemplate,
   118  		integration.StreamTestOptSleepAfterInput(500*time.Millisecond),
   119  		integration.StreamTestOptSleepAfterOutput(500*time.Millisecond),
   120  		integration.StreamTestOptPort(resource.GetPort("5672/tcp")),
   121  		integration.StreamTestOptVarOne("false"),
   122  	)
   123  })