...

Source file src/edge-infra.dev/pkg/f8n/devinfra/repo/owners/policybot/policy/common/trigger_test.go

Documentation: edge-infra.dev/pkg/f8n/devinfra/repo/owners/policybot/policy/common

     1  // Copyright 2020 Palantir Technologies, Inc.
     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  package common
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestTriggerMatches(t *testing.T) {
    24  	tests := []struct {
    25  		Trigger Trigger
    26  		Flags   Trigger
    27  		Matches bool
    28  	}{
    29  		{TriggerCommit, TriggerCommit, true},
    30  		{TriggerCommit | TriggerLabel, TriggerCommit, true},
    31  		{TriggerCommit | TriggerLabel, TriggerLabel, true},
    32  		{TriggerAll, TriggerStatus, true},
    33  		{TriggerStatic, TriggerCommit, false},
    34  		{TriggerAll, TriggerStatic, false},
    35  	}
    36  
    37  	for _, test := range tests {
    38  		if test.Matches {
    39  			assert.True(t, test.Trigger.Matches(test.Flags), "expected %s to match %s", test.Trigger, test.Flags)
    40  		} else {
    41  			assert.False(t, test.Trigger.Matches(test.Flags), "expected %s to not match %s", test.Trigger, test.Flags)
    42  		}
    43  	}
    44  }
    45  
    46  func TestTriggerString(t *testing.T) {
    47  	tests := []struct {
    48  		Trigger Trigger
    49  		String  string
    50  	}{
    51  		{TriggerStatic, "Trigger(0x0=Static)"},
    52  		{TriggerCommit, "Trigger(0x1=Commit)"},
    53  		{TriggerCommit | TriggerReview | TriggerStatus, "Trigger(0x15=Commit|Review|Status)"},
    54  	}
    55  
    56  	for _, test := range tests {
    57  		assert.Equal(t, test.String, test.Trigger.String(), "trigger 0x%x formatted incorrectly", test.Trigger)
    58  	}
    59  }
    60  

View as plain text