github.com/googleapis/api-linter@v1.65.2/lint/rule_urls_test.go (about)

     1  package lint
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestCoreRuleURL(t *testing.T) {
     8  	tests := []struct {
     9  		name string
    10  		rule string
    11  		url  string
    12  	}{
    13  		{"CoreRule", "core::0122::camel-case-uris", "https://linter.aip.dev/122/camel-case-uris"},
    14  		{"NotCoreRule", "test::0122::camel-case-uris", ""},
    15  	}
    16  
    17  	for _, test := range tests {
    18  		t.Run(test.name, func(t *testing.T) {
    19  			if got := coreRuleURL(test.rule); got != test.url {
    20  				t.Errorf("coreRuleURL(%s) got %s, but want %s", test.name, got, test.url)
    21  			}
    22  		})
    23  	}
    24  }
    25  
    26  func TestClientLibrariesRuleURL(t *testing.T) {
    27  	tests := []struct {
    28  		name string
    29  		rule string
    30  		url  string
    31  	}{
    32  		{"ClientLibrariesRule", "client-libraries::4232::repeated-fields", "https://linter.aip.dev/4232/repeated-fields"},
    33  		{"NotClientLibrariesRule", "test::0122::camel-case-uris", ""},
    34  	}
    35  
    36  	for _, test := range tests {
    37  		t.Run(test.name, func(t *testing.T) {
    38  			if got := clientLibrariesRuleURL(test.rule); got != test.url {
    39  				t.Errorf("clientLibrariesRuleUrl(%s) got %s, but want %s", test.name, got, test.url)
    40  			}
    41  		})
    42  	}
    43  }
    44  
    45  func TestCloudRuleURL(t *testing.T) {
    46  	tests := []struct {
    47  		name string
    48  		rule string
    49  		url  string
    50  	}{
    51  		{"CloudRule", "cloud::2500::generic-fields", "https://linter.aip.dev/2500/generic-fields"},
    52  		{"NotCloudRule", "test::0122::camel-case-uris", ""},
    53  	}
    54  
    55  	for _, test := range tests {
    56  		t.Run(test.name, func(t *testing.T) {
    57  			if got := cloudRuleURL(test.rule); got != test.url {
    58  				t.Errorf("cloudRuleUrl(%s) got %s, but want %s", test.name, got, test.url)
    59  			}
    60  		})
    61  	}
    62  }
    63  
    64  func TestGetRuleURL(t *testing.T) {
    65  	mapping1 := func(name string) string {
    66  		if name == "one" {
    67  			return "ONE"
    68  		}
    69  		return ""
    70  	}
    71  	mapping2 := func(name string) string {
    72  		if name == "two" {
    73  			return "TWO"
    74  		}
    75  		return ""
    76  	}
    77  	ruleURLMappings := []func(string) string{mapping1, mapping2}
    78  
    79  	tests := []struct {
    80  		name     string
    81  		ruleName string
    82  		ruleURL  string
    83  	}{
    84  		{"MappingOne", "one", "ONE"},
    85  		{"MappingTwo", "two", "TWO"},
    86  		{"NoMapping", "zero", ""},
    87  	}
    88  
    89  	for _, test := range tests {
    90  		t.Run(test.name, func(t *testing.T) {
    91  			if got := getRuleURL(test.ruleName, ruleURLMappings); got != test.ruleURL {
    92  				t.Errorf("getRuleURL(%s) got %s, but want %s", test.ruleName, got, test.ruleURL)
    93  			}
    94  		})
    95  	}
    96  }