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
=== added directory 'utils/series'
=== added file 'utils/series/series.go'
--- utils/series/series.go 1970-01-01 00:00:00 +0000
+++ utils/series/series.go 2015-07-24 14:21:26 +0000
@@ -0,0 +1,111 @@
1package series
2
3import (
4 "fmt"
5)
6
7// seriesInformation is a not exported type that stores the information related to a series.
8type seriesInformation struct {
9 Name string
10 Packages []string
11}
12
13// Series stores information about a series like the chroot name and the packages it needs to be installed in the chroot.
14type Series struct {
15 seriesData map[string]seriesInformation
16}
17
18// NewSeries returns a Series structure filled with its data and ready to be used.
19func NewSeries() Series {
20 s := Series{
21 seriesData: make(map[string]seriesInformation),
22 }
23
24 // set all the series data
25 // this could be done with an xml or json file
26 // in the future to be more flexible and easy
27 // to modify
28 var vivid seriesInformation
29 vivid.Name = "ubuntu-sdk-15.04"
30 vivid.Packages = []string{"golang-go",
31 "golang-go-linux-arm",
32 "golang-go-dbus-dev",
33 "golang-go-xdg-dev",
34 "golang-gocheck-dev",
35 "golang-gosqlite-dev",
36 "golang-uuid-dev",
37 "libgcrypt20-dev:armhf",
38 "libglib2.0-dev:armhf",
39 "libwhoopsie-dev:armhf",
40 "libdbus-1-dev:armhf",
41 "libnih-dbus-dev:armhf",
42 "libsqlite3-dev:armhf",
43 "crossbuild-essential-armhf",
44 }
45 s.seriesData["vivid"] = vivid
46
47 // TODO add future series (wily, etc)
48
49 return s
50}
51
52// GetValidSeries returns a list containing the valid series names.
53func (s Series) GetValidSeries() []string {
54 series := make([]string, len(s.seriesData), len(s.seriesData))
55 var i int
56 for k, _ := range s.seriesData {
57 series[i] = k
58 i++
59 }
60 return series
61}
62
63// PrintValidSeries prints the list of valid series, so the user can choose which one to use.
64func (s Series) PrintValidSeries() {
65 for _, k := range s.GetValidSeries() {
66 fmt.Printf(" %s\n", k)
67 }
68}
69
70// CheckValid checks if the given series name is valid.
71// Parameters:
72// series: the series name to check if it's valid (vidid, for example)
73//
74// Returns: true if the series name is valid, false otherwise. If the series name is not valid it prints the available ones.
75func (s Series) CheckValid(series string) bool {
76 if _, ok := s.seriesData[series]; !ok {
77 fmt.Println("ERROR: Wrong series name.")
78 fmt.Println("Valid series are:")
79 s.PrintValidSeries()
80 return false
81 }
82 return true
83}
84
85// GetChrootName returns the name to the chroot for the given series.
86// Parameters:
87// series: the series name to get the chroot name (vidid, for example)
88//
89// Returns: If the series does not exist it prints the list of valid series and returns an
90// empty string, otherwise it returns the chroot name (for example: ubuntu-sdk-15.04)
91func (s Series) GetChrootName(series string) string {
92 if s.CheckValid(series) {
93 return s.seriesData[series].Name
94 } else {
95 return ""
96 }
97}
98
99// GetPackagesList returns the list of packages needed by the given series.
100// Parameters:
101// series: the series name to get the list of needed packages.
102//
103// If the series does not exist it prints the list of valid series and returns an
104// empty string slice.
105func (s Series) GetPackagesList(series string) []string {
106 if s.CheckValid(series) {
107 return s.seriesData[series].Packages
108 } else {
109 return []string{}
110 }
111}
0112
=== added file 'utils/series/series_test.go'
--- utils/series/series_test.go 1970-01-01 00:00:00 +0000
+++ utils/series/series_test.go 2015-07-24 14:21:26 +0000
@@ -0,0 +1,85 @@
1package series_test
2
3import (
4 . "gopkg.in/check.v1"
5 "launchpad.net/go-unityscopes/v2/utils/series"
6 "launchpad.net/go-unityscopes/v2/utils/testutils"
7 "testing"
8)
9
10type S struct{}
11
12func init() {
13 Suite(&S{})
14}
15
16func TestAll(t *testing.T) {
17 TestingT(t)
18}
19
20func (s *S) TestPrintValidSeries(c *C) {
21 var capture testutils.CaptureStdOut
22 // capture stdout to instpect that the result of the print method is correct.
23 capture.Capture()
24
25 series := series.NewSeries()
26 series.PrintValidSeries()
27
28 capture.StopCapture()
29
30 c.Check(capture.GetCapuredOut(), Equals, " vivid\n")
31}
32
33func (s *S) TestGetValidSeries(c *C) {
34 series := series.NewSeries()
35 c.Check(series.GetValidSeries(), DeepEquals, []string{"vivid"})
36}
37
38func (s *S) TestCheckValidSeriesOK(c *C) {
39 series := series.NewSeries()
40 c.Check(series.CheckValid("vivid"), Equals, true)
41}
42
43func (s *S) TestCheckValidSeriesBadKey(c *C) {
44 series := series.NewSeries()
45 c.Check(series.CheckValid("bad-key"), Equals, false)
46}
47
48func (s *S) TestCheckValidSeriesEmptyKey(c *C) {
49 series := series.NewSeries()
50 c.Check(series.CheckValid(""), Equals, false)
51}
52
53func (s *S) TestCheckValidSeriesChrootName(c *C) {
54 series := series.NewSeries()
55 c.Check(series.GetChrootName("vivid"), Equals, "ubuntu-sdk-15.04")
56}
57
58func (s *S) TestCheckValidBadSeriesChrootName(c *C) {
59 series := series.NewSeries()
60 c.Check(series.GetChrootName("bad-key"), Equals, "")
61}
62
63func (s *S) TestCheckValidSeriesPackages(c *C) {
64 series := series.NewSeries()
65 c.Check(series.GetPackagesList("vivid"), DeepEquals, []string{"golang-go",
66 "golang-go-linux-arm",
67 "golang-go-dbus-dev",
68 "golang-go-xdg-dev",
69 "golang-gocheck-dev",
70 "golang-gosqlite-dev",
71 "golang-uuid-dev",
72 "libgcrypt20-dev:armhf",
73 "libglib2.0-dev:armhf",
74 "libwhoopsie-dev:armhf",
75 "libdbus-1-dev:armhf",
76 "libnih-dbus-dev:armhf",
77 "libsqlite3-dev:armhf",
78 "crossbuild-essential-armhf",
79 })
80}
81
82func (s *S) TestCheckValidBadSeriesPackages(c *C) {
83 series := series.NewSeries()
84 c.Check(series.GetPackagesList("bad-key"), DeepEquals, []string{})
85}

Subscribers

People subscribed via source and target branches

to all changes: