github.com/sirkon/goproxy@v1.4.8/internal/get/tag_test.go (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package get
     6  
     7  import "testing"
     8  
     9  var selectTagTestTags = []string{
    10  	"go.r58",
    11  	"go.r58.1",
    12  	"go.r59",
    13  	"go.r59.1",
    14  	"go.r61",
    15  	"go.r61.1",
    16  	"go.weekly.2010-01-02",
    17  	"go.weekly.2011-10-12",
    18  	"go.weekly.2011-10-12.1",
    19  	"go.weekly.2011-10-14",
    20  	"go.weekly.2011-11-01",
    21  	"go1",
    22  	"go1.0.1",
    23  	"go1.999",
    24  	"go1.9.2",
    25  	"go5",
    26  
    27  	// these should be ignored:
    28  	"release.r59",
    29  	"release.r59.1",
    30  	"release",
    31  	"weekly.2011-10-12",
    32  	"weekly.2011-10-12.1",
    33  	"weekly",
    34  	"foo",
    35  	"bar",
    36  	"go.f00",
    37  	"go!r60",
    38  	"go.1999-01-01",
    39  	"go.2x",
    40  	"go.20000000000000",
    41  	"go.2.",
    42  	"go.2.0",
    43  	"go2x",
    44  	"go20000000000000",
    45  	"go2.",
    46  	"go2.0",
    47  }
    48  
    49  var selectTagTests = []struct {
    50  	version  string
    51  	selected string
    52  }{
    53  	/*
    54  		{"release.r57", ""},
    55  		{"release.r58.2", "go.r58.1"},
    56  		{"release.r59", "go.r59"},
    57  		{"release.r59.1", "go.r59.1"},
    58  		{"release.r60", "go.r59.1"},
    59  		{"release.r60.1", "go.r59.1"},
    60  		{"release.r61", "go.r61"},
    61  		{"release.r66", "go.r61.1"},
    62  		{"weekly.2010-01-01", ""},
    63  		{"weekly.2010-01-02", "go.weekly.2010-01-02"},
    64  		{"weekly.2010-01-02.1", "go.weekly.2010-01-02"},
    65  		{"weekly.2010-01-03", "go.weekly.2010-01-02"},
    66  		{"weekly.2011-10-12", "go.weekly.2011-10-12"},
    67  		{"weekly.2011-10-12.1", "go.weekly.2011-10-12.1"},
    68  		{"weekly.2011-10-13", "go.weekly.2011-10-12.1"},
    69  		{"weekly.2011-10-14", "go.weekly.2011-10-14"},
    70  		{"weekly.2011-10-14.1", "go.weekly.2011-10-14"},
    71  		{"weekly.2011-11-01", "go.weekly.2011-11-01"},
    72  		{"weekly.2014-01-01", "go.weekly.2011-11-01"},
    73  		{"weekly.3000-01-01", "go.weekly.2011-11-01"},
    74  		{"go1", "go1"},
    75  		{"go1.1", "go1.0.1"},
    76  		{"go1.998", "go1.9.2"},
    77  		{"go1.1000", "go1.999"},
    78  		{"go6", "go5"},
    79  
    80  		// faulty versions:
    81  		{"release.f00", ""},
    82  		{"weekly.1999-01-01", ""},
    83  		{"junk", ""},
    84  		{"", ""},
    85  		{"go2x", ""},
    86  		{"go200000000000", ""},
    87  		{"go2.", ""},
    88  		{"go2.0", ""},
    89  	*/
    90  	{"anything", "go1"},
    91  }
    92  
    93  func TestSelectTag(t *testing.T) {
    94  	for _, c := range selectTagTests {
    95  		selected := selectTag(c.version, selectTagTestTags)
    96  		if selected != c.selected {
    97  			t.Errorf("selectTag(%q) = %q, want %q", c.version, selected, c.selected)
    98  		}
    99  	}
   100  }