diff options
| author | Maciej Borzecki <maciej.zenon.borzecki@canonical.com> | 2019-07-04 11:30:04 +0200 |
|---|---|---|
| committer | Maciej Borzecki <maciej.zenon.borzecki@canonical.com> | 2019-07-04 11:31:11 +0200 |
| commit | e3d940e7708fabd7c30eef843545c0b9b96e29e0 (patch) | |
| tree | ca56582ac998d2068a909b59cca31fc00632a0c7 /daemon | |
| parent | 5a11ef6f939b0fa50509f2ce0574f8b5efaf09a2 (diff) | |
daemon: mock reading of build ID
It is assumed that the test binary has a build ID, either added by Go toolchain (happens by default with Go 1.10+) or by gcc (only when built with CGO). Since osutil package no longer requires CGO, the latter case does take place. When running with Go 1.9, the tests assuming build ID presence fail because the Go toolchain never added one. Instead of working around the toolchain, add mocking where needed. Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Diffstat (limited to 'daemon')
| -rw-r--r-- | daemon/api_test.go | 10 | ||||
| -rw-r--r-- | daemon/export_test.go | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/daemon/api_test.go b/daemon/api_test.go index 1fe7a16587..24f4f7a5e9 100644 --- a/daemon/api_test.go +++ b/daemon/api_test.go @@ -1031,8 +1031,9 @@ func (s *apiSuite) TestSysInfo(c *check.C) { // reload dirs for release info to have effect dirs.SetRootDir(dirs.GlobalRootDir) - buildID, err := osutil.MyBuildID() - c.Assert(err, check.IsNil) + buildID := "this-is-my-build-id" + restore = MockBuildID(buildID) + defer restore() sysInfoCmd.GET(sysInfoCmd, nil, nil).ServeHTTP(rec, nil) c.Check(rec.Code, check.Equals, 200) @@ -1101,8 +1102,9 @@ func (s *apiSuite) TestSysInfoLegacyRefresh(c *check.C) { }) c.Assert(err, check.IsNil) - buildID, err := osutil.MyBuildID() - c.Assert(err, check.IsNil) + buildID := "this-is-my-build-id" + restore = MockBuildID(buildID) + defer restore() sysInfoCmd.GET(sysInfoCmd, nil, nil).ServeHTTP(rec, nil) c.Check(rec.Code, check.Equals, 200) diff --git a/daemon/export_test.go b/daemon/export_test.go index bdc0bf58ae..57ac73f5b4 100644 --- a/daemon/export_test.go +++ b/daemon/export_test.go @@ -41,3 +41,11 @@ func MockMuxVars(vars func(*http.Request) map[string]string) (restore func()) { muxVars = old } } + +func MockBuildID(mock string) (restore func()) { + old := buildID + buildID = mock + return func() { + buildID = old + } +} |
