github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/jujuc/jujuctesting/suite.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 "time" 8 9 "github.com/juju/testing" 10 gc "gopkg.in/check.v1" 11 "gopkg.in/juju/charm.v6" 12 13 "github.com/juju/juju/core/application" 14 ) 15 16 // ContextSuite is the base suite for testing jujuc.Context-related code. 17 type ContextSuite struct { 18 Stub *testing.Stub 19 Unit string 20 } 21 22 func (s *ContextSuite) SetUpTest(c *gc.C) { 23 s.Stub = &testing.Stub{} 24 s.Unit = "u/0" 25 } 26 27 // NewInfo builds a ContextInfo with basic default data. 28 func (s *ContextSuite) NewInfo() *ContextInfo { 29 var info ContextInfo 30 31 timestamp := time.Date(2200, time.November, 05, 15, 29, 12, 30, time.UTC) 32 gsStatus := application.GoalStateStatus{ 33 Status: "active", 34 Since: ×tamp, 35 } 36 37 info.Unit.Name = s.Unit 38 info.ConfigSettings = charm.Settings{ 39 "empty": nil, 40 "monsters": false, 41 "spline-reticulation": 45.0, 42 "title": "My Title", 43 "username": "admin001", 44 } 45 info.GoalState = application.GoalState{ 46 Units: application.UnitsGoalState{ 47 "mysql/0": gsStatus, 48 }, 49 Relations: map[string]application.UnitsGoalState{ 50 "db": { 51 "mysql/0": gsStatus, 52 }, 53 "server": { 54 "wordpress/0": gsStatus, 55 }, 56 }, 57 } 58 info.AvailabilityZone = "us-east-1a" 59 info.PublicAddress = "gimli.minecraft.testing.invalid" 60 info.PrivateAddress = "192.168.0.99" 61 return &info 62 } 63 64 // NewHookContext builds a jujuc.Context test double. 65 func (s *ContextSuite) NewHookContext() (*Context, *ContextInfo) { 66 info := s.NewInfo() 67 return NewContext(s.Stub, info), info 68 }