github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/commands/alpha/rpkg/copy/command_test.go (about)

     1  // Copyright 2022 Google LLC
     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 copy
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestNextRevisionNumber(t *testing.T) {
    24  	testcases := map[string]struct {
    25  		input    string
    26  		expected string
    27  		err      string
    28  	}{
    29  		"invalid": {
    30  			input: "alskdfj",
    31  			err:   "invalid revision format alskdfj; explicit --revision flag is required",
    32  		},
    33  		"no dots": {
    34  			input:    "v4",
    35  			expected: "v5",
    36  		},
    37  		"one dot": {
    38  			input:    "v3.1",
    39  			expected: "v3.2",
    40  		},
    41  		"two dots": {
    42  			input:    "v1.2.3",
    43  			expected: "v1.2.4",
    44  		},
    45  	}
    46  
    47  	for name, tc := range testcases {
    48  		t.Run(name, func(t *testing.T) {
    49  			output, err := nextRevisionNumber(tc.input)
    50  			if tc.err != "" {
    51  				require.Error(t, err)
    52  				require.Equal(t, tc.err, err.Error())
    53  			} else {
    54  				require.NoError(t, err)
    55  				require.Equal(t, tc.expected, output)
    56  			}
    57  		})
    58  	}
    59  }