gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/github/reviver/github_test.go (about)

     1  // Copyright 2020 The gVisor Authors.
     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 reviver
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestParseIssueNo(t *testing.T) {
    22  	testCases := []struct {
    23  		issue     string
    24  		expectErr bool
    25  		expected  int
    26  	}{
    27  		{
    28  			issue:    "gvisor.dev/issue/123",
    29  			expected: 123,
    30  		},
    31  		{
    32  			issue:    "gvisor.dev/issue/123/",
    33  			expected: 123,
    34  		},
    35  		{
    36  			issue:    "not a url",
    37  			expected: 0,
    38  		},
    39  		{
    40  			issue:     "gvisor.dev/issue//",
    41  			expectErr: true,
    42  		},
    43  	}
    44  
    45  	for _, tc := range testCases {
    46  		t.Run(tc.issue, func(t *testing.T) {
    47  			id, err := parseIssueNo(tc.issue)
    48  			if err != nil && !tc.expectErr {
    49  				t.Errorf("got error: %v", err)
    50  			} else if tc.expected != id {
    51  				t.Errorf("got: %v, want: %v", id, tc.expected)
    52  			}
    53  		})
    54  	}
    55  }