// Set up the instrumented test server for a local run by running in a docker
// container on the local host
Set up the instrumented test server for a local run by running in a docker
container on the local host
// Set up the instrumented test server for a local run by running in a docker // container on the local host
func SetupLocal(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error) {
	pubsubInfo, cleanupTf, err := setuptf.SetupTf(
		ctx,
		args.ProjectID,
		args.TestRunID,
		localTfDir,
		map[string]string{},
		logger,
	)
	if err != nil {
		return nil, cleanupTf, err
	}
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		return nil, cleanupTf, err
	}
	cli.NegotiateAPIVersion(ctx)
	createdRes, err := createContainer(ctx, cli, args, pubsubInfo, logger)
	if err != nil {
		if errdefs.IsNotFound(err) {
			err = fmt.Errorf(
				`docker image not found, try running "docker pull %v": %w`,
				args.Local.Image,
				err,
			)
		}
		return nil, cleanupTf, err
	}
	if len(createdRes.Warnings) != 0 {
		logger.Printf("Started with warnings: %v", createdRes.Warnings)
	}
	containerID := createdRes.ID
	removeContainer := func() {
		defer cleanupTf()
		err = cli.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{Force: true})
		if err != nil {
			logger.Panic(err)
		}
	}
	err = cli.ContainerStart(ctx, containerID, types.ContainerStartOptions{})
	if err != nil {
		return nil, removeContainer, err
	}
	cleanup := func() {
		logger.Printf("Stopping and removing container ID %v\n", containerID)
		timeout := (time.Second * 15)
		err = cli.ContainerStop(ctx, containerID, &timeout)
		defer removeContainer()
		if err != nil {
			logger.Panic(err)
		}
	}
	err = startForwardingContainerLogs(ctx, cli, containerID, logger)
	if err != nil {
		return nil, cleanup, err
	}
	client, err := testclient.New(ctx, args.ProjectID, pubsubInfo)
	if err != nil {
		return nil, cleanup, err
	}
	return client, cleanup, err
}
func SetupLocal ( ctx context . Context , args * Args , logger * log . Logger , ) ( * testclient . Client , Cleanup , error ) { pubsubInfo , cleanupTf , err := setuptf . SetupTf ( ctx , args . ProjectID , args . TestRunID , localTfDir , map [ string ] string { } , logger , ) if err != nil { return nil , cleanupTf , err } cli , err := client . NewClientWithOpts ( client . FromEnv ) if err != nil { return nil , cleanupTf , err } cli . NegotiateAPIVersion ( ctx ) createdRes , err := createContainer ( ctx , cli , args , pubsubInfo , logger ) if err != nil { if errdefs . IsNotFound ( err ) { err = fmt . Errorf ( `docker image not found, try running "docker pull %v": %w` , args . Local . Image , err , ) } return nil , cleanupTf , err } if len ( createdRes . Warnings ) != 0 { logger . Printf ( " " , createdRes . Warnings ) } containerID := createdRes . ID removeContainer := func ( ) { defer cleanupTf ( ) err = cli . ContainerRemove ( ctx , containerID , types . ContainerRemoveOptions { Force : true } ) if err != nil { logger . Panic ( err ) } } err = cli . ContainerStart ( ctx , containerID , types . ContainerStartOptions { } ) if err != nil { return nil , removeContainer , err } cleanup := func ( ) { logger . Printf ( " \n " , containerID ) timeout := ( time . Second * 15 ) err = cli . ContainerStop ( ctx , containerID , & timeout ) defer removeContainer ( ) if err != nil { logger . Panic ( err ) } } err = startForwardingContainerLogs ( ctx , cli , containerID , logger ) if err != nil { return nil , cleanup , err } client , err := testclient . New ( ctx , args . ProjectID , pubsubInfo ) if err != nil { return nil , cleanup , err } return client , cleanup , err }
Set up the instrumented test server for a local run by running in a docker
container on the local host
Set up the instrumented test server for a local run by running in a docker container on the local host