github.com/argoproj/argo-events@v1.9.1/eventsources/sources/gerrit/validate_test.go (about)

     1  /*
     2  Copyright 2018 BlackRock, Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package gerrit
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"os"
    23  	"testing"
    24  
    25  	"github.com/ghodss/yaml"
    26  	"github.com/stretchr/testify/assert"
    27  
    28  	"github.com/argoproj/argo-events/eventsources/sources"
    29  	"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
    30  )
    31  
    32  func TestValidateEventSource(t *testing.T) {
    33  	listener := &EventListener{}
    34  
    35  	err := listener.ValidateEventSource(context.Background())
    36  	assert.Error(t, err)
    37  	assert.Equal(t, "projects cannot be empty", err.Error())
    38  
    39  	content, err := os.ReadFile(fmt.Sprintf("%s/%s", sources.EventSourceDir, "gerrit.yaml"))
    40  	assert.Nil(t, err)
    41  
    42  	var eventSource *v1alpha1.EventSource
    43  	err = yaml.Unmarshal(content, &eventSource)
    44  	assert.Nil(t, err)
    45  	assert.NotNil(t, eventSource.Spec.Gerrit)
    46  
    47  	for name, value := range eventSource.Spec.Gerrit {
    48  		fmt.Println(name)
    49  		l := &EventListener{
    50  			GerritEventSource: value,
    51  		}
    52  		err := l.ValidateEventSource(context.Background())
    53  		assert.NoError(t, err)
    54  	}
    55  }