github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/plugin/checker/internal/version/comments_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package version
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestExtractVersionFromComment(t *testing.T) {
    14  	testCases := []struct {
    15  		input    string
    16  		expected string
    17  	}{
    18  		{
    19  			input:    "This is a comment.\n\nMinimum server version: 1.2.3-rc1\n",
    20  			expected: "1.2.3-rc1",
    21  		},
    22  		{
    23  			input:    "This is a comment.\n\nMinimum server version: 1.2.3\n",
    24  			expected: "1.2.3",
    25  		},
    26  		{
    27  			input:    "This is a comment.\n\nMinimum server version: 1.2\n",
    28  			expected: "1.2",
    29  		},
    30  		{
    31  			input:    "This is a comment.\n\nMinimum server version: 1\n",
    32  			expected: "",
    33  		},
    34  		{
    35  			input:    "This is a comment.\n",
    36  			expected: "",
    37  		},
    38  		{
    39  			input:    "",
    40  			expected: "",
    41  		},
    42  	}
    43  
    44  	for _, tc := range testCases {
    45  		t.Run(fmt.Sprintf("%+v", tc), func(t *testing.T) {
    46  			assert.Equal(t, tc.expected, ExtractMinimumVersionFromComment(tc.input))
    47  		})
    48  	}
    49  }