github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/jujuc/jujuctesting/unit.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuctesting
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"gopkg.in/juju/charm.v6"
     9  
    10  	"github.com/juju/juju/apiserver/params"
    11  	"github.com/juju/juju/core/application"
    12  )
    13  
    14  // Unit holds the values for the hook context.
    15  type Unit struct {
    16  	Name           string
    17  	ConfigSettings charm.Settings
    18  	GoalState      application.GoalState
    19  	ContainerSpec  string
    20  	CloudSpec      params.CloudSpec
    21  }
    22  
    23  // ContextUnit is a test double for jujuc.ContextUnit.
    24  type ContextUnit struct {
    25  	contextBase
    26  	info *Unit
    27  }
    28  
    29  // UnitName implements jujuc.ContextUnit.
    30  func (c *ContextUnit) UnitName() string {
    31  	c.stub.AddCall("UnitName")
    32  	c.stub.NextErr()
    33  
    34  	return c.info.Name
    35  }
    36  
    37  // ConfigSettings implements jujuc.ContextUnit.
    38  func (c *ContextUnit) ConfigSettings() (charm.Settings, error) {
    39  	c.stub.AddCall("ConfigSettings")
    40  	if err := c.stub.NextErr(); err != nil {
    41  		return nil, errors.Trace(err)
    42  	}
    43  
    44  	return c.info.ConfigSettings, nil
    45  }
    46  
    47  // GoalState implements jujuc.ContextUnit.
    48  func (c *ContextUnit) GoalState() (*application.GoalState, error) {
    49  	c.stub.AddCall("GoalState")
    50  	if err := c.stub.NextErr(); err != nil {
    51  		return nil, errors.Trace(err)
    52  	}
    53  	return &c.info.GoalState, nil
    54  }
    55  
    56  func (c *ContextUnit) SetPodSpec(specYaml string) error {
    57  	c.stub.AddCall("SetPodSpec", specYaml)
    58  	if err := c.stub.NextErr(); err != nil {
    59  		return errors.Trace(err)
    60  	}
    61  	c.info.ContainerSpec = specYaml
    62  	return nil
    63  }
    64  
    65  func (c *ContextUnit) CloudSpec() (*params.CloudSpec, error) {
    66  	c.stub.AddCall("CloudSpec")
    67  	if err := c.stub.NextErr(); err != nil {
    68  		return nil, errors.Trace(err)
    69  	}
    70  	c.info.CloudSpec = params.CloudSpec{}
    71  	return &c.info.CloudSpec, nil
    72  }