github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/common/labelsort/labelsort_test.go (about)

     1  // Copyright 2016 The rkt 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 labelsort
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/appc/spec/schema/types"
    21  )
    22  
    23  func TestRankedName(t *testing.T) {
    24  	tests := []struct {
    25  		li string
    26  		lj string
    27  
    28  		expected bool
    29  	}{
    30  		{
    31  			"version", "os",
    32  			true,
    33  		},
    34  		{
    35  			"os", "version",
    36  			false,
    37  		},
    38  		{
    39  			"version", "a",
    40  			true,
    41  		},
    42  		{
    43  			"a", "os",
    44  			false,
    45  		},
    46  		{
    47  			"os", "a",
    48  			true,
    49  		},
    50  		{
    51  			"", "os",
    52  			false,
    53  		},
    54  		{
    55  			"os", "",
    56  			true,
    57  		},
    58  		{
    59  			"a", "version",
    60  			false,
    61  		},
    62  		{
    63  			"a", "b",
    64  			true,
    65  		},
    66  		{
    67  			"b", "a",
    68  			false,
    69  		},
    70  		{
    71  			"a", "a",
    72  			false,
    73  		},
    74  		{
    75  			"version", "version",
    76  			false,
    77  		},
    78  	}
    79  
    80  	for i, tt := range tests {
    81  		li := types.Label{
    82  			Name: types.ACIdentifier(tt.li),
    83  		}
    84  
    85  		lj := types.Label{
    86  			Name: types.ACIdentifier(tt.lj),
    87  		}
    88  
    89  		if result := RankedName(li, lj); result != tt.expected {
    90  			t.Errorf("test %d expected %q < %q = %t but got %t", i, tt.li, tt.lj, tt.expected, result)
    91  		}
    92  	}
    93  }