You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: upgrader_test.go
    path of file: ./repos/juju/worker/upgrader
    
    the code of the file until where you have to start completion: // Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package upgrader_test

import (
	"fmt"
	"os"
	"path/filepath"
	stdtesting "testing"
	"time"

	"github.com/juju/clock/testclock"
	"github.com/juju/errors"
	"github.com/juju/loggo"
	"github.com/juju/names/v5"
	"github.com/juju/testing"
	jc "github.com/juju/testing/checkers"
	"github.com/juju/utils/v3"
	"github.com/juju/utils/v3/symlink"
	"github.com/juju/version/v2"
	"github.com/juju/worker/v3"
	"github.com/juju/worker/v3/workertest"
	gc "gopkg.in/check.v1"

	"github.com/juju/juju/agent"
	agenttools "github.com/juju/juju/agent/tools"
	"github.com/juju/juju/api"
	upgraderapi "github.com/juju/juju/api/agent/upgrader"
	agenterrors 
    
func (s *UpgraderSuite) TestChecksSpaceBeforeDownloading(c *gc.C) {
	stor := s.DefaultToolsStorage
	oldTools := envtesting.PrimeTools(c, stor, s.DataDir(), s.Environ.Config().AgentStream(),
		version.MustParseBinary("5.4.3-ubuntu-amd64"))
	s.patchVersion(oldTools.Version)

	newTools := envtesting.AssertUploadFakeToolsVersions(
		c, stor, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(),
		version.MustParseBinary("5.4.5-ubuntu-amd64"))[0]
	err := statetesting.SetAgentVersion(s.State, newTools.Version.Number)
	c.Assert(err, jc.ErrorIsNil)

	// We want to wait for the model to settle so that we get a single event
	// from the version watcher.
	// If we start the worker too quickly after setting the new tools,
	// it is possible to get 2 watcher changes - the guaranteed initial event
	// and *then* the one for the change.
	s.WaitForModelWatchersIdle(c, s.State.ModelUUID())

	var diskSpaceStub testing.Stub
	diskSpaceStub.SetErrors(nil, errors.Errorf("full-up"))
	diskSpaceChecked := make(chan struct{}, 1)

	u, err := upgrader.NewAgentUpgrader(upgrader.Config{
		Clock:                       s.clock,
		Logger:                      loggo.GetLogger("test"),
		State:                       upgraderapi.NewState(s.state),
		AgentConfig:                 agentConfig(s.machine.Tag(), s.DataDir()),
		OrigAgentVersion:            s.confVersion,
		UpgradeStepsWaiter:          s.upgradeStepsComplete,
		InitialUpgradeCheckComplete: s.initialCheckComplete,
		CheckDiskSpace: func(dir string, size uint64) error {
			diskSpaceStub.AddCall("CheckDiskSpace", dir, size)

			// CheckDiskSpace is called twice in checkForSpace.
			// We only care that we arrived there, so if we've already buffered
			// a write, just proceed.
			select {
			case diskSpaceChecked <- struct{}{}:
			default:
			}

			return diskSpaceStub.NextErr()
		},
	})
	c.Assert(err, jc.ErrorIsNil)

	select {
	case <-diskSpaceChecked:
		workertest.CleanKill(c, u)
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out waiting for disk space check.")
	}

	s.expectInitialUpgradeCheckNotDone(c)

	c.Assert(diskSpaceStub.Calls(), gc.HasLen, 2)
	diskSpaceStub.CheckCall(c, 0, "CheckDiskSpace", s.DataDir(), upgrades.MinDiskSpaceMib)
	diskSpaceStub.CheckCall(c, 1, "CheckDiskSpace", os.TempDir(), upgrades.MinDiskSpaceMib)

	_, err = agenttools.ReadTools(s.DataDir(), newTools.Version)
	c.Assert(err, gc.ErrorMatches, `cannot read agent metadata in directory.*: no such file or directory`)
}