Merge lp:~xavi-garcia-mena/go-unityscopes/utils-series into lp:go-unityscopes/v2

Proposed by Xavi Garcia
Status: Needs review
Proposed branch: lp:~xavi-garcia-mena/go-unityscopes/utils-series
Merge into: lp:go-unityscopes/v2
Prerequisite: lp:~xavi-garcia-mena/go-unityscopes/utils-command
Diff against target: 206 lines (+196/-0)
2 files modified
utils/series/series.go (+111/-0)
utils/series/series_test.go (+85/-0)
To merge this branch: bzr merge lp:~xavi-garcia-mena/go-unityscopes/utils-series
Reviewer Review Type Date Requested Status
Unity API Team Pending
Review via email: mp+265833@code.launchpad.net

Commit message

Added series package, to represent the possible combinations for chroots when crosscompiling.

Description of the change

Added series package, to represent the possible combinations for chroots when crosscompiling.

To post a comment you must log in.

Unmerged revisions

71. By Xavi Garcia

Added utilites series information to describe the different configurations we can face when crosscompiling go scopes

70. By Xavi Garcia

Added utils directory with tools for building. Added common test utils package. Added utils command package to run system commands

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'utils/series'
2=== added file 'utils/series/series.go'
3--- utils/series/series.go 1970-01-01 00:00:00 +0000
4+++ utils/series/series.go 2015-07-24 14:21:26 +0000
5@@ -0,0 +1,111 @@
6+package series
7+
8+import (
9+ "fmt"
10+)
11+
12+// seriesInformation is a not exported type that stores the information related to a series.
13+type seriesInformation struct {
14+ Name string
15+ Packages []string
16+}
17+
18+// Series stores information about a series like the chroot name and the packages it needs to be installed in the chroot.
19+type Series struct {
20+ seriesData map[string]seriesInformation
21+}
22+
23+// NewSeries returns a Series structure filled with its data and ready to be used.
24+func NewSeries() Series {
25+ s := Series{
26+ seriesData: make(map[string]seriesInformation),
27+ }
28+
29+ // set all the series data
30+ // this could be done with an xml or json file
31+ // in the future to be more flexible and easy
32+ // to modify
33+ var vivid seriesInformation
34+ vivid.Name = "ubuntu-sdk-15.04"
35+ vivid.Packages = []string{"golang-go",
36+ "golang-go-linux-arm",
37+ "golang-go-dbus-dev",
38+ "golang-go-xdg-dev",
39+ "golang-gocheck-dev",
40+ "golang-gosqlite-dev",
41+ "golang-uuid-dev",
42+ "libgcrypt20-dev:armhf",
43+ "libglib2.0-dev:armhf",
44+ "libwhoopsie-dev:armhf",
45+ "libdbus-1-dev:armhf",
46+ "libnih-dbus-dev:armhf",
47+ "libsqlite3-dev:armhf",
48+ "crossbuild-essential-armhf",
49+ }
50+ s.seriesData["vivid"] = vivid
51+
52+ // TODO add future series (wily, etc)
53+
54+ return s
55+}
56+
57+// GetValidSeries returns a list containing the valid series names.
58+func (s Series) GetValidSeries() []string {
59+ series := make([]string, len(s.seriesData), len(s.seriesData))
60+ var i int
61+ for k, _ := range s.seriesData {
62+ series[i] = k
63+ i++
64+ }
65+ return series
66+}
67+
68+// PrintValidSeries prints the list of valid series, so the user can choose which one to use.
69+func (s Series) PrintValidSeries() {
70+ for _, k := range s.GetValidSeries() {
71+ fmt.Printf(" %s\n", k)
72+ }
73+}
74+
75+// CheckValid checks if the given series name is valid.
76+// Parameters:
77+// series: the series name to check if it's valid (vidid, for example)
78+//
79+// Returns: true if the series name is valid, false otherwise. If the series name is not valid it prints the available ones.
80+func (s Series) CheckValid(series string) bool {
81+ if _, ok := s.seriesData[series]; !ok {
82+ fmt.Println("ERROR: Wrong series name.")
83+ fmt.Println("Valid series are:")
84+ s.PrintValidSeries()
85+ return false
86+ }
87+ return true
88+}
89+
90+// GetChrootName returns the name to the chroot for the given series.
91+// Parameters:
92+// series: the series name to get the chroot name (vidid, for example)
93+//
94+// Returns: If the series does not exist it prints the list of valid series and returns an
95+// empty string, otherwise it returns the chroot name (for example: ubuntu-sdk-15.04)
96+func (s Series) GetChrootName(series string) string {
97+ if s.CheckValid(series) {
98+ return s.seriesData[series].Name
99+ } else {
100+ return ""
101+ }
102+}
103+
104+// GetPackagesList returns the list of packages needed by the given series.
105+// Parameters:
106+// series: the series name to get the list of needed packages.
107+//
108+// If the series does not exist it prints the list of valid series and returns an
109+// empty string slice.
110+func (s Series) GetPackagesList(series string) []string {
111+ if s.CheckValid(series) {
112+ return s.seriesData[series].Packages
113+ } else {
114+ return []string{}
115+ }
116+}
117
118=== added file 'utils/series/series_test.go'
119--- utils/series/series_test.go 1970-01-01 00:00:00 +0000
120+++ utils/series/series_test.go 2015-07-24 14:21:26 +0000
121@@ -0,0 +1,85 @@
122+package series_test
123+
124+import (
125+ . "gopkg.in/check.v1"
126+ "launchpad.net/go-unityscopes/v2/utils/series"
127+ "launchpad.net/go-unityscopes/v2/utils/testutils"
128+ "testing"
129+)
130+
131+type S struct{}
132+
133+func init() {
134+ Suite(&S{})
135+}
136+
137+func TestAll(t *testing.T) {
138+ TestingT(t)
139+}
140+
141+func (s *S) TestPrintValidSeries(c *C) {
142+ var capture testutils.CaptureStdOut
143+ // capture stdout to instpect that the result of the print method is correct.
144+ capture.Capture()
145+
146+ series := series.NewSeries()
147+ series.PrintValidSeries()
148+
149+ capture.StopCapture()
150+
151+ c.Check(capture.GetCapuredOut(), Equals, " vivid\n")
152+}
153+
154+func (s *S) TestGetValidSeries(c *C) {
155+ series := series.NewSeries()
156+ c.Check(series.GetValidSeries(), DeepEquals, []string{"vivid"})
157+}
158+
159+func (s *S) TestCheckValidSeriesOK(c *C) {
160+ series := series.NewSeries()
161+ c.Check(series.CheckValid("vivid"), Equals, true)
162+}
163+
164+func (s *S) TestCheckValidSeriesBadKey(c *C) {
165+ series := series.NewSeries()
166+ c.Check(series.CheckValid("bad-key"), Equals, false)
167+}
168+
169+func (s *S) TestCheckValidSeriesEmptyKey(c *C) {
170+ series := series.NewSeries()
171+ c.Check(series.CheckValid(""), Equals, false)
172+}
173+
174+func (s *S) TestCheckValidSeriesChrootName(c *C) {
175+ series := series.NewSeries()
176+ c.Check(series.GetChrootName("vivid"), Equals, "ubuntu-sdk-15.04")
177+}
178+
179+func (s *S) TestCheckValidBadSeriesChrootName(c *C) {
180+ series := series.NewSeries()
181+ c.Check(series.GetChrootName("bad-key"), Equals, "")
182+}
183+
184+func (s *S) TestCheckValidSeriesPackages(c *C) {
185+ series := series.NewSeries()
186+ c.Check(series.GetPackagesList("vivid"), DeepEquals, []string{"golang-go",
187+ "golang-go-linux-arm",
188+ "golang-go-dbus-dev",
189+ "golang-go-xdg-dev",
190+ "golang-gocheck-dev",
191+ "golang-gosqlite-dev",
192+ "golang-uuid-dev",
193+ "libgcrypt20-dev:armhf",
194+ "libglib2.0-dev:armhf",
195+ "libwhoopsie-dev:armhf",
196+ "libdbus-1-dev:armhf",
197+ "libnih-dbus-dev:armhf",
198+ "libsqlite3-dev:armhf",
199+ "crossbuild-essential-armhf",
200+ })
201+}
202+
203+func (s *S) TestCheckValidBadSeriesPackages(c *C) {
204+ series := series.NewSeries()
205+ c.Check(series.GetPackagesList("bad-key"), DeepEquals, []string{})
206+}

Subscribers

People subscribed via source and target branches

to all changes: