github.com/googleapis/api-linter@v1.65.2/rules/rules_test.go (about)

     1  package rules
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/googleapis/api-linter/lint"
     8  )
     9  
    10  func TestAddAIPRules(t *testing.T) {
    11  	wantError := errors.New("test")
    12  	tests := []struct {
    13  		name          string
    14  		addRulesFuncs []addRulesFuncType
    15  		err           error
    16  	}{
    17  		{
    18  			name:          "EmptyRules_NoError",
    19  			addRulesFuncs: nil,
    20  			err:           nil,
    21  		},
    22  		{
    23  			name: "AddingRules_NoError",
    24  			addRulesFuncs: []addRulesFuncType{
    25  				func(lint.RuleRegistry) error { return nil },
    26  			},
    27  			err: nil,
    28  		},
    29  		{
    30  			name: "ReturnError",
    31  			addRulesFuncs: []addRulesFuncType{
    32  				func(lint.RuleRegistry) error { return wantError },
    33  			},
    34  			err: wantError,
    35  		},
    36  	}
    37  	for _, test := range tests {
    38  		t.Run(test.name, func(t *testing.T) {
    39  			err := addAIPRules(lint.NewRuleRegistry(), test.addRulesFuncs)
    40  			if err != test.err {
    41  				t.Errorf("addAIPRules got error %v, but want %v", err, test.err)
    42  			}
    43  		})
    44  	}
    45  }
    46  
    47  func TestAdd(t *testing.T) {
    48  	if err := Add(lint.NewRuleRegistry()); err != nil {
    49  		t.Errorf("Add got an error: %v", err)
    50  	}
    51  }