github.com/argoproj/argo-events@v1.9.1/controllers/eventsource/validate_test.go (about)

     1  package eventsource
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestValidate(t *testing.T) {
    10  	t.Run("validate calendar eventsource", func(t *testing.T) {
    11  		testEventSource := fakeEmptyEventSource()
    12  		testEventSource.Spec.Calendar = fakeCalendarEventSourceMap("test")
    13  		err := ValidateEventSource(testEventSource)
    14  		assert.NoError(t, err)
    15  	})
    16  
    17  	t.Run("validate good mixed types eventsource", func(t *testing.T) {
    18  		testEventSource := fakeEmptyEventSource()
    19  		testEventSource.Spec.Kafka = fakeKafkaEventSourceMap("test1")
    20  		testEventSource.Spec.MQTT = fakeMQTTEventSourceMap("test2")
    21  		err := ValidateEventSource(testEventSource)
    22  		assert.NoError(t, err)
    23  	})
    24  
    25  	t.Run("validate bad mixed types eventsource", func(t *testing.T) {
    26  		testEventSource := fakeEmptyEventSource()
    27  		testEventSource.Spec.Kafka = fakeKafkaEventSourceMap("test1")
    28  		testEventSource.Spec.Webhook = fakeWebhookEventSourceMap("test2")
    29  		err := ValidateEventSource(testEventSource)
    30  		assert.Error(t, err)
    31  		assert.Equal(t, "event sources with rolling update and recreate update strategy can not be put together", err.Error())
    32  	})
    33  
    34  	t.Run("validate bad mixed types eventsource - duplicated name", func(t *testing.T) {
    35  		testEventSource := fakeEmptyEventSource()
    36  		testEventSource.Spec.Kafka = fakeKafkaEventSourceMap("test")
    37  		testEventSource.Spec.MQTT = fakeMQTTEventSourceMap("test")
    38  		err := ValidateEventSource(testEventSource)
    39  		assert.Error(t, err)
    40  		assert.Equal(t, "more than one \"test\" found in the spec", err.Error())
    41  	})
    42  }