Merge lp:~elopio/snappy-tests-job/merge into lp:snappy-tests-job

Proposed by Leo Arias
Status: Merged
Merged at revision: 62
Proposed branch: lp:~elopio/snappy-tests-job/merge
Merge into: lp:snappy-tests-job
Diff against target: 104 lines (+46/-1)
3 files modified
snappy-tests-job/main.go (+9/-1)
source/source.go (+12/-0)
source/source_test.go (+25/-0)
To merge this branch: bzr merge lp:~elopio/snappy-tests-job/merge
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+268698@code.launchpad.net

Commit message

Added a target flag to merge the source before running the tests.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

I added tests and tried it. Self-approving to give it a go in jenkins.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'snappy-tests-job/main.go'
--- snappy-tests-job/main.go 2015-08-21 02:40:46 +0000
+++ snappy-tests-job/main.go 2015-08-21 04:29:18 +0000
@@ -58,6 +58,8 @@
58 "Channel of the image, defaults to "+defaultChannel)58 "Channel of the image, defaults to "+defaultChannel)
59 src = flag.String("src", defaultSrc,59 src = flag.String("src", defaultSrc,
60 "Branch from which to get the source code, defaults to "+defaultSrc)60 "Branch from which to get the source code, defaults to "+defaultSrc)
61 target = flag.String("target", "",
62 "Target branch to be merged with the src branch, defaults to not merging src with any branch")
6163
62 commandTpl = flag.String("command", defaultCommandTpl,64 commandTpl = flag.String("command", defaultCommandTpl,
63 "Command template, should include the testBed ip as %s, defaults to '"+defaultCommandTpl+"'")65 "Command template, should include the testBed ip as %s, defaults to '"+defaultCommandTpl+"'")
@@ -68,7 +70,13 @@
68 // TODO: we need a waitGroup here to run things more efficiently70 // TODO: we need a waitGroup here to run things more efficiently
69 utilHandler := utils.NewBasicHandler()71 utilHandler := utils.NewBasicHandler()
70 sourceHandler := source.NewBzrHandler(utilHandler)72 sourceHandler := source.NewBzrHandler(utilHandler)
71 sourcePath, err := sourceHandler.Get(*src)73 var err error
74 var sourcePath string
75 if *target == "" {
76 sourcePath, err = sourceHandler.Get(*src)
77 } else {
78 sourcePath, err = sourceHandler.Merge(*src, *target)
79 }
72 if err != nil {80 if err != nil {
73 log.Panicf("Error getting %s into %s", *src, sourcePath)81 log.Panicf("Error getting %s into %s", *src, sourcePath)
74 }82 }
7583
=== modified file 'source/source.go'
--- source/source.go 2015-08-21 02:21:02 +0000
+++ source/source.go 2015-08-21 04:29:18 +0000
@@ -37,6 +37,7 @@
37// Sourcer is the interface satisfied by all the source handlers37// Sourcer is the interface satisfied by all the source handlers
38type Sourcer interface {38type Sourcer interface {
39 Get(string) (string, error)39 Get(string) (string, error)
40 Merge(string, string) (string, error)
40}41}
4142
42// BzrHandler is a source handler for bazaar43// BzrHandler is a source handler for bazaar
@@ -60,6 +61,17 @@
60 return filepath.Join(path, targetSubdir), err61 return filepath.Join(path, targetSubdir), err
61}62}
6263
64// Merge merges two branches and returns the path to the merged source.
65func (handler *BzrHandler) Merge(source string, target string) (string, error) {
66 path, err := handler.Get(target)
67 if err == nil {
68 log.Printf("*** Merging %s with %s ***", target, source)
69 params := utils.NewExecCommandParams(path, []string{"bzr", "merge", source}, true)
70 _, err = handler.util.ExecCommand(params)
71 }
72 return path, err
73}
74
63// NewBzrHandler returns a pointer to a new bzr source handler75// NewBzrHandler returns a pointer to a new bzr source handler
64func NewBzrHandler(util utils.Utilizer) *BzrHandler {76func NewBzrHandler(util utils.Utilizer) *BzrHandler {
65 return &BzrHandler{util: util}77 return &BzrHandler{util: util}
6678
=== modified file 'source/source_test.go'
--- source/source_test.go 2015-08-21 02:20:10 +0000
+++ source/source_test.go 2015-08-21 04:29:18 +0000
@@ -32,6 +32,7 @@
32)32)
3333
34const testRepo = "lp:snappy"34const testRepo = "lp:snappy"
35const testSource = "lp:~snappy-dev/snappy/test-branch"
3536
36var _ = check.Suite(&sourceSuite{})37var _ = check.Suite(&sourceSuite{})
3738
@@ -91,6 +92,25 @@
91 s.fakeUtil.ExecCalls[pullCmd]))92 s.fakeUtil.ExecCalls[pullCmd]))
92}93}
9394
95func (s *sourceSuite) TestMergeCallsGetAndMergeCommand(c *check.C) {
96 s.subject.Merge(testSource, testRepo)
97
98 pullCmd := pullCmd()
99 c.Check(s.fakeUtil.ExecCalls[pullCmd], check.Equals, 1,
100 check.Commentf("The pull command %s was not called", pullCmd))
101 mergeCmd := mergeCmd()
102 c.Check(s.fakeUtil.ExecCalls[mergeCmd], check.Equals, 1,
103 check.Commentf("The merge command %s was not called", mergeCmd))
104}
105
106func (s *sourceSuite) TestMergeReturnValue(c *check.C) {
107 path, err := s.subject.Merge(testSource, testRepo)
108 expected := expectedReturnPath()
109
110 c.Assert(path, check.Equals, expected, check.Commentf("Unexpected return value path %s", path))
111 c.Assert(err, check.IsNil, check.Commentf("Unexpected return error %s", err))
112}
113
94func expectedBasePath() string {114func expectedBasePath() string {
95 return filepath.Join(targetPath, strconv.Itoa(os.Getpid()), basePkg)115 return filepath.Join(targetPath, strconv.Itoa(os.Getpid()), basePkg)
96}116}
@@ -103,3 +123,8 @@
103 params := utils.NewExecCommandParams(expectedBasePath(), []string{"bzr", "branch", testRepo, targetSubdir}, true)123 params := utils.NewExecCommandParams(expectedBasePath(), []string{"bzr", "branch", testRepo, targetSubdir}, true)
104 return params.String()124 return params.String()
105}125}
126
127func mergeCmd() string {
128 params := utils.NewExecCommandParams(expectedReturnPath(), []string{"bzr", "merge", testSource}, true)
129 return params.String()
130}

Subscribers

People subscribed via source and target branches

to all changes: