~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/utils/series/supportedseries_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package series_test
 
5
 
 
6
import (
 
7
        "github.com/juju/testing"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
11
        "github.com/juju/utils/os"
 
12
        "github.com/juju/utils/series"
 
13
)
 
14
 
 
15
type supportedSeriesSuite struct {
 
16
        testing.CleanupSuite
 
17
}
 
18
 
 
19
var _ = gc.Suite(&supportedSeriesSuite{})
 
20
 
 
21
func (s *supportedSeriesSuite) SetUpTest(c *gc.C) {
 
22
        s.CleanupSuite.SetUpTest(c)
 
23
        cleanup := series.SetSeriesVersions(make(map[string]string))
 
24
        s.AddCleanup(func(*gc.C) { cleanup() })
 
25
}
 
26
 
 
27
var getOSFromSeriesTests = []struct {
 
28
        series string
 
29
        want   os.OSType
 
30
        err    string
 
31
}{{
 
32
        series: "precise",
 
33
        want:   os.Ubuntu,
 
34
}, {
 
35
        series: "win2012r2",
 
36
        want:   os.Windows,
 
37
}, {
 
38
        series: "win2016nano",
 
39
        want:   os.Windows,
 
40
}, {
 
41
        series: "mountainlion",
 
42
        want:   os.OSX,
 
43
}, {
 
44
        series: "centos7",
 
45
        want:   os.CentOS,
 
46
}, {
 
47
        series: "arch",
 
48
        want:   os.Arch,
 
49
}, {
 
50
        series: "",
 
51
        err:    "series \"\" not valid",
 
52
},
 
53
}
 
54
 
 
55
func (s *supportedSeriesSuite) TestGetOSFromSeries(c *gc.C) {
 
56
        for _, t := range getOSFromSeriesTests {
 
57
                got, err := series.GetOSFromSeries(t.series)
 
58
                if t.err != "" {
 
59
                        c.Assert(err, gc.ErrorMatches, t.err)
 
60
                } else {
 
61
                        c.Check(err, jc.ErrorIsNil)
 
62
                        c.Assert(got, gc.Equals, t.want)
 
63
                }
 
64
        }
 
65
}
 
66
 
 
67
func (s *supportedSeriesSuite) TestUnknownOSFromSeries(c *gc.C) {
 
68
        _, err := series.GetOSFromSeries("Xuanhuaceratops")
 
69
        c.Assert(err, jc.Satisfies, series.IsUnknownOSForSeriesError)
 
70
        c.Assert(err, gc.ErrorMatches, `unknown OS for series: "Xuanhuaceratops"`)
 
71
}
 
72
 
 
73
func setSeriesTestData() {
 
74
        series.SetSeriesVersions(map[string]string{
 
75
                "trusty":      "14.04",
 
76
                "utopic":      "14.10",
 
77
                "win7":        "win7",
 
78
                "win81":       "win81",
 
79
                "win2016nano": "win2016nano",
 
80
                "centos7":     "centos7",
 
81
                "arch":        "rolling",
 
82
        })
 
83
}
 
84
 
 
85
func (s *supportedSeriesSuite) TestOSSupportedSeries(c *gc.C) {
 
86
        setSeriesTestData()
 
87
        supported := series.OSSupportedSeries(os.Ubuntu)
 
88
        c.Assert(supported, jc.SameContents, []string{"trusty", "utopic"})
 
89
        supported = series.OSSupportedSeries(os.Windows)
 
90
        c.Assert(supported, jc.SameContents, []string{"win7", "win81", "win2016nano"})
 
91
        supported = series.OSSupportedSeries(os.CentOS)
 
92
        c.Assert(supported, jc.SameContents, []string{"centos7"})
 
93
        supported = series.OSSupportedSeries(os.Arch)
 
94
        c.Assert(supported, jc.SameContents, []string{"arch"})
 
95
}
 
96
 
 
97
func (s *supportedSeriesSuite) TestVersionSeriesValid(c *gc.C) {
 
98
        setSeriesTestData()
 
99
        seriesResult, err := series.VersionSeries("14.04")
 
100
        c.Assert(err, jc.ErrorIsNil)
 
101
        c.Assert("trusty", gc.DeepEquals, seriesResult)
 
102
}
 
103
 
 
104
func (s *supportedSeriesSuite) TestVersionSeriesEmpty(c *gc.C) {
 
105
        setSeriesTestData()
 
106
        _, err := series.VersionSeries("")
 
107
        c.Assert(err, gc.ErrorMatches, `.*unknown series for version: "".*`)
 
108
}
 
109
 
 
110
func (s *supportedSeriesSuite) TestVersionSeriesInvalid(c *gc.C) {
 
111
        setSeriesTestData()
 
112
        _, err := series.VersionSeries("73655")
 
113
        c.Assert(err, gc.ErrorMatches, `.*unknown series for version: "73655".*`)
 
114
}
 
115
 
 
116
func (s *supportedSeriesSuite) TestSeriesVersionEmpty(c *gc.C) {
 
117
        setSeriesTestData()
 
118
        _, err := series.SeriesVersion("")
 
119
        c.Assert(err, gc.ErrorMatches, `.*unknown version for series: "".*`)
 
120
}
 
121
 
 
122
func (s *supportedSeriesSuite) TestIsWindowsNano(c *gc.C) {
 
123
        var isWindowsNanoTests = []struct {
 
124
                series   string
 
125
                expected bool
 
126
        }{
 
127
                {"win2016nano", true},
 
128
                {"win2016", false},
 
129
                {"win2012r2", false},
 
130
                {"trusty", false},
 
131
        }
 
132
 
 
133
        for _, t := range isWindowsNanoTests {
 
134
                c.Assert(series.IsWindowsNano(t.series), gc.Equals, t.expected)
 
135
        }
 
136
}
 
137
 
 
138
func (s *supportedSeriesSuite) TestLatestLts(c *gc.C) {
 
139
        table := []struct {
 
140
                latest, want string
 
141
        }{
 
142
                {"testseries", "testseries"},
 
143
                {"", "xenial"},
 
144
        }
 
145
        for _, test := range table {
 
146
                series.SetLatestLtsForTesting(test.latest)
 
147
                got := series.LatestLts()
 
148
                c.Assert(got, gc.Equals, test.want)
 
149
        }
 
150
}
 
151
func (s *supportedSeriesSuite) TestSetLatestLtsForTesting(c *gc.C) {
 
152
        table := []struct {
 
153
                value, want string
 
154
        }{
 
155
                {"1", "xenial"}, {"2", "1"}, {"3", "2"}, {"4", "3"},
 
156
        }
 
157
        for _, test := range table {
 
158
                got := series.SetLatestLtsForTesting(test.value)
 
159
                c.Assert(got, gc.Equals, test.want)
 
160
        }
 
161
}
 
162
 
 
163
func (s *supportedSeriesSuite) TestSupportedLts(c *gc.C) {
 
164
        got := series.SupportedLts()
 
165
        want := []string{"precise", "trusty", "xenial"}
 
166
        c.Assert(got, gc.DeepEquals, want)
 
167
}