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

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