github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/environs/testing/bootstrap.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/juju/cmd/v3/cmdtesting"
    10  	"github.com/juju/loggo"
    11  	"github.com/juju/testing"
    12  	"github.com/juju/utils/v3/ssh"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/cloudconfig/instancecfg"
    16  	"github.com/juju/juju/cmd/modelcmd"
    17  	"github.com/juju/juju/environs"
    18  	envcontext "github.com/juju/juju/environs/context"
    19  	"github.com/juju/juju/environs/instances"
    20  	"github.com/juju/juju/provider/common"
    21  )
    22  
    23  var logger = loggo.GetLogger("juju.environs.testing")
    24  
    25  // DisableFinishBootstrap disables common.FinishBootstrap so that tests
    26  // do not attempt to SSH to non-existent machines. The result is a function
    27  // that restores finishBootstrap.
    28  func DisableFinishBootstrap() func() {
    29  	f := func(
    30  		environs.BootstrapContext,
    31  		ssh.Client,
    32  		environs.Environ,
    33  		envcontext.ProviderCallContext,
    34  		instances.Instance,
    35  		*instancecfg.InstanceConfig,
    36  		environs.BootstrapDialOpts,
    37  	) error {
    38  		logger.Infof("provider/common.FinishBootstrap is disabled")
    39  		return nil
    40  	}
    41  	return testing.PatchValue(&common.FinishBootstrap, f)
    42  }
    43  
    44  // BootstrapContext creates a simple bootstrap execution context.
    45  func BootstrapContext(ctx context.Context, c *gc.C) environs.BootstrapContext {
    46  	return modelcmd.BootstrapContext(ctx, cmdtesting.Context(c))
    47  }
    48  
    49  func BootstrapTODOContext(c *gc.C) environs.BootstrapContext {
    50  	return BootstrapContext(context.TODO(), c)
    51  }