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
1=== modified file 'snappy-tests-job/main.go'
2--- snappy-tests-job/main.go 2015-08-21 02:40:46 +0000
3+++ snappy-tests-job/main.go 2015-08-21 04:29:18 +0000
4@@ -58,6 +58,8 @@
5 "Channel of the image, defaults to "+defaultChannel)
6 src = flag.String("src", defaultSrc,
7 "Branch from which to get the source code, defaults to "+defaultSrc)
8+ target = flag.String("target", "",
9+ "Target branch to be merged with the src branch, defaults to not merging src with any branch")
10
11 commandTpl = flag.String("command", defaultCommandTpl,
12 "Command template, should include the testBed ip as %s, defaults to '"+defaultCommandTpl+"'")
13@@ -68,7 +70,13 @@
14 // TODO: we need a waitGroup here to run things more efficiently
15 utilHandler := utils.NewBasicHandler()
16 sourceHandler := source.NewBzrHandler(utilHandler)
17- sourcePath, err := sourceHandler.Get(*src)
18+ var err error
19+ var sourcePath string
20+ if *target == "" {
21+ sourcePath, err = sourceHandler.Get(*src)
22+ } else {
23+ sourcePath, err = sourceHandler.Merge(*src, *target)
24+ }
25 if err != nil {
26 log.Panicf("Error getting %s into %s", *src, sourcePath)
27 }
28
29=== modified file 'source/source.go'
30--- source/source.go 2015-08-21 02:21:02 +0000
31+++ source/source.go 2015-08-21 04:29:18 +0000
32@@ -37,6 +37,7 @@
33 // Sourcer is the interface satisfied by all the source handlers
34 type Sourcer interface {
35 Get(string) (string, error)
36+ Merge(string, string) (string, error)
37 }
38
39 // BzrHandler is a source handler for bazaar
40@@ -60,6 +61,17 @@
41 return filepath.Join(path, targetSubdir), err
42 }
43
44+// Merge merges two branches and returns the path to the merged source.
45+func (handler *BzrHandler) Merge(source string, target string) (string, error) {
46+ path, err := handler.Get(target)
47+ if err == nil {
48+ log.Printf("*** Merging %s with %s ***", target, source)
49+ params := utils.NewExecCommandParams(path, []string{"bzr", "merge", source}, true)
50+ _, err = handler.util.ExecCommand(params)
51+ }
52+ return path, err
53+}
54+
55 // NewBzrHandler returns a pointer to a new bzr source handler
56 func NewBzrHandler(util utils.Utilizer) *BzrHandler {
57 return &BzrHandler{util: util}
58
59=== modified file 'source/source_test.go'
60--- source/source_test.go 2015-08-21 02:20:10 +0000
61+++ source/source_test.go 2015-08-21 04:29:18 +0000
62@@ -32,6 +32,7 @@
63 )
64
65 const testRepo = "lp:snappy"
66+const testSource = "lp:~snappy-dev/snappy/test-branch"
67
68 var _ = check.Suite(&sourceSuite{})
69
70@@ -91,6 +92,25 @@
71 s.fakeUtil.ExecCalls[pullCmd]))
72 }
73
74+func (s *sourceSuite) TestMergeCallsGetAndMergeCommand(c *check.C) {
75+ s.subject.Merge(testSource, testRepo)
76+
77+ pullCmd := pullCmd()
78+ c.Check(s.fakeUtil.ExecCalls[pullCmd], check.Equals, 1,
79+ check.Commentf("The pull command %s was not called", pullCmd))
80+ mergeCmd := mergeCmd()
81+ c.Check(s.fakeUtil.ExecCalls[mergeCmd], check.Equals, 1,
82+ check.Commentf("The merge command %s was not called", mergeCmd))
83+}
84+
85+func (s *sourceSuite) TestMergeReturnValue(c *check.C) {
86+ path, err := s.subject.Merge(testSource, testRepo)
87+ expected := expectedReturnPath()
88+
89+ c.Assert(path, check.Equals, expected, check.Commentf("Unexpected return value path %s", path))
90+ c.Assert(err, check.IsNil, check.Commentf("Unexpected return error %s", err))
91+}
92+
93 func expectedBasePath() string {
94 return filepath.Join(targetPath, strconv.Itoa(os.Getpid()), basePkg)
95 }
96@@ -103,3 +123,8 @@
97 params := utils.NewExecCommandParams(expectedBasePath(), []string{"bzr", "branch", testRepo, targetSubdir}, true)
98 return params.String()
99 }
100+
101+func mergeCmd() string {
102+ params := utils.NewExecCommandParams(expectedReturnPath(), []string{"bzr", "merge", testSource}, true)
103+ return params.String()
104+}

Subscribers

People subscribed via source and target branches

to all changes: