github.com/leowmjw/otto@v0.2.1-0.20160126165905-6400716cf085/otto/testing_components.go (about)

     1  package otto
     2  
     3  import (
     4  	"github.com/hashicorp/otto/app"
     5  	"github.com/hashicorp/otto/foundation"
     6  	"github.com/hashicorp/otto/infrastructure"
     7  )
     8  
     9  // TestInfra adds a mock infrastructure with the given name to the
    10  // core config and returns it.
    11  func TestInfra(t TestT, n string, c *CoreConfig) *infrastructure.Mock {
    12  	if c.Infrastructures == nil {
    13  		c.Infrastructures = make(map[string]infrastructure.Factory)
    14  	}
    15  
    16  	result := new(infrastructure.Mock)
    17  	c.Infrastructures[n] = func() (infrastructure.Infrastructure, error) {
    18  		return result, nil
    19  	}
    20  
    21  	return result
    22  }
    23  
    24  // TestApp adds a mock app with the given tuple to the core config.
    25  func TestApp(t TestT, tuple app.Tuple, c *CoreConfig) *app.Mock {
    26  	if c.Apps == nil {
    27  		c.Apps = make(map[app.Tuple]app.Factory)
    28  	}
    29  
    30  	result := new(app.Mock)
    31  	c.Apps[tuple] = func() (app.App, error) {
    32  		return result, nil
    33  	}
    34  
    35  	return result
    36  }
    37  
    38  // TestFoundation adds a mock foundation with the given tuple to the core config.
    39  func TestFoundation(t TestT, tuple foundation.Tuple, c *CoreConfig) *foundation.Mock {
    40  	if c.Foundations == nil {
    41  		c.Foundations = make(map[foundation.Tuple]foundation.Factory)
    42  	}
    43  
    44  	result := new(foundation.Mock)
    45  	c.Foundations[tuple] = func() (foundation.Foundation, error) {
    46  		return result, nil
    47  	}
    48  
    49  	return result
    50  }