github.com/cloudwego/kitex@v0.9.0/tool/cmd/kitex/args/args_test.go (about)

     1  /*
     2   * Copyright 2023 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package args
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/cloudwego/kitex/internal/test"
    23  )
    24  
    25  func Test_versionSatisfied(t *testing.T) {
    26  	t.Run("lower", func(t *testing.T) {
    27  		test.Assert(t, !versionSatisfied("v1.0.0", "v1.0.1"))
    28  		test.Assert(t, !versionSatisfied("v1.0.1", "v1.1.0"))
    29  		test.Assert(t, !versionSatisfied("v1.1.1", "v2.0.0"))
    30  	})
    31  
    32  	t.Run("equal", func(t *testing.T) {
    33  		test.Assert(t, versionSatisfied("v1.2.3", "v1.2.3"))
    34  	})
    35  
    36  	t.Run("higher", func(t *testing.T) {
    37  		test.Assert(t, versionSatisfied("v1.2.4", "v1.2.3"))
    38  		test.Assert(t, versionSatisfied("v1.2.3", "v1.1.4"))
    39  		test.Assert(t, versionSatisfied("v2.2.3", "v1.3.4"))
    40  	})
    41  
    42  	t.Run("suffix", func(t *testing.T) {
    43  		test.Assert(t, !versionSatisfied("v1.2.3", "v1.2.3-rc1")) // required shouldn't have suffix
    44  		test.Assert(t, !versionSatisfied("v1.2.3-rc1", "v1.2.3")) // suffix means lower
    45  	})
    46  	t.Run("no prefix", func(t *testing.T) {
    47  		test.Assert(t, versionSatisfied("v1.2.3", "1.2.3"))
    48  		test.Assert(t, versionSatisfied("1.2.3", "v1.2.3"))
    49  		test.Assert(t, versionSatisfied("1.2.3", "1.2.3"))
    50  		test.Assert(t, !versionSatisfied("v1.2.3", "1.2.4"))
    51  		test.Assert(t, !versionSatisfied("1.2.3", "v1.2.4"))
    52  		test.Assert(t, !versionSatisfied("1.2.3", "1.2.4"))
    53  	})
    54  }