~fgimenez/snappy-cloud-image/list-private-images

« back to all changes in this revision

Viewing changes to runner/runner_test.go

  • Committer: Federico Gimenez
  • Date: 2015-08-13 16:05:31 UTC
  • mfrom: (56.1.1 arch)
  • Revision ID: fgimenez@canonical.com-20150813160531-71nhysd4n16yehxe
mergedĀ lp:~elopio/snappy-tests-job/arch

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        fakeUtil   *testhelpers.FakeUtils
38
38
        subject    Runner
39
39
        ip         string
 
40
        arch       string
40
41
        path       string
41
42
        goPath     string
42
43
        cmdTpl     string
63
64
}
64
65
 
65
66
func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {
66
 
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
 
67
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
67
68
 
68
 
        runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.goPath, false)
 
69
        runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, false)
69
70
        c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
70
71
                check.Commentf("The command %s was not called", runCmd))
71
72
}
72
73
 
73
74
func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {
74
 
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
 
75
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
75
76
 
76
77
        installGodepCmd := installGodepCmd(s.path, s.goPath)
77
78
        c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,
79
80
}
80
81
 
81
82
func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {
82
 
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
 
83
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
83
84
 
84
85
        installDepCmd := installDepCmd(s.path, s.goPath)
85
86
        c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,
89
90
func (s *runnerSuite) TestRunReturnError(c *check.C) {
90
91
        s.fakeUtil.FailExec = true
91
92
 
92
 
        err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
 
93
        err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
93
94
 
94
95
        c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))
95
96
}
96
97
 
97
98
func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {
98
99
        fromBranch := true
99
 
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, fromBranch)
100
 
 
101
 
        runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.goPath, fromBranch)
102
 
        c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
103
 
                check.Commentf("The command %s was not called", runCmd))
104
 
}
105
 
 
106
 
func runCmd(path, cmdTpl, ip, goPath string, fromBranch bool) string {
107
 
        var snappyFromBranch string
 
100
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, fromBranch)
 
101
 
 
102
        runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, fromBranch)
 
103
        c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
 
104
                check.Commentf("The command %s was not called", runCmd))
 
105
}
 
106
 
 
107
func (s *runnerSuite) TestRunCallRunTestsWithArchCommand(c *check.C) {
 
108
        arch := "testarch"
 
109
        s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.fromBranch)
 
110
 
 
111
        runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.fromBranch)
 
112
        c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
 
113
                check.Commentf("The command %s was not called", runCmd))
 
114
}
 
115
 
 
116
func runCmd(path, cmdTpl, ip, arch, goPath string, fromBranch bool) string {
 
117
        var args []string
 
118
        if arch != "" {
 
119
                args = append(args, "-arch "+arch)
 
120
        }
108
121
        if fromBranch {
109
 
                snappyFromBranch = "-snappy-from-branch"
 
122
                args = append(args, "-snappy-from-branch")
110
123
        }
111
124
 
112
 
        cmd := fmt.Sprintf(cmdTpl, ip, snappyFromBranch)
 
125
        cmd := fmt.Sprintf(cmdTpl, ip, strings.Join(args, " "))
113
126
        params := utils.NewExecCommandParams(path, strings.Fields(cmd), true)
114
127
        params.AppendEnv(fmt.Sprintf("GOPATH=%s", goPath))
115
128
        return params.String()