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

     1  package github
     2  
     3  import (
     4  	"testing"
     5  
     6  	gh "github.com/google/go-github/v50/github"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestCompareHook(t *testing.T) {
    11  	assert.False(t, compareHook(nil, "https://google.com/", []string{}))
    12  
    13  	assert.True(t, compareHook(&gh.Hook{
    14  		Config: map[string]interface{}{
    15  			"url": "https://google.com/",
    16  		},
    17  		Events: []string{"*"},
    18  	}, "https://google.com/", []string{"*"}))
    19  
    20  	assert.False(t, compareHook(&gh.Hook{
    21  		Config: map[string]interface{}{
    22  			"url": "https://google.com/",
    23  		},
    24  		Events: []string{"pull_request"},
    25  	}, "https://google.com/", []string{"*"}))
    26  
    27  	assert.False(t, compareHook(&gh.Hook{
    28  		Config: map[string]interface{}{
    29  			"url": "https://example.com/",
    30  		},
    31  		Events: []string{"pull_request"},
    32  	}, "https://google.com/", []string{"*"}))
    33  }
    34  
    35  func TestGetHook(t *testing.T) {
    36  	hooks := []*gh.Hook{
    37  		{
    38  			Config: map[string]interface{}{
    39  				"url": "https://example.com/",
    40  			},
    41  			Events: []string{"pull_request"},
    42  		},
    43  		{
    44  			Config: map[string]interface{}{
    45  				"url": "https://example.com/",
    46  			},
    47  			Events: []string{"*"},
    48  		},
    49  	}
    50  
    51  	assert.Equal(t, hooks[1], getHook(hooks, "https://example.com/", []string{"*"}))
    52  	assert.Nil(t, getHook(hooks, "https://example.com/", []string{"does_not_exist"}))
    53  }