github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/featuretests/charm_upgrade_test.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package featuretests 5 6 import ( 7 "fmt" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/juju/testing" 13 "github.com/juju/juju/state" 14 ) 15 16 type CharmUpgradeSuite struct { 17 testing.JujuConnSuite 18 19 appOneName string 20 appOne *state.Application 21 22 appTwoName string 23 } 24 25 func (s *CharmUpgradeSuite) SetUpTest(c *gc.C) { 26 s.JujuConnSuite.SetUpTest(c) 27 28 s.appOneName = "app1" 29 charmOne := s.AddTestingCharm(c, "upgrade-charm1") 30 31 var err error 32 s.appOne, err = s.State.AddApplication(state.AddApplicationArgs{ 33 Name: s.appOneName, 34 Charm: charmOne, 35 }) 36 c.Assert(err, jc.ErrorIsNil) 37 unitOne, err := s.appOne.AddUnit(state.AddUnitParams{}) 38 c.Assert(err, jc.ErrorIsNil) 39 unitOne.SetCharmURL(charmOne.URL()) 40 41 s.appTwoName = "app2" 42 charmTwo := s.AddTestingCharm(c, "upgrade-charm2") 43 appTwo, err := s.State.AddApplication(state.AddApplicationArgs{ 44 Name: s.appTwoName, 45 Charm: charmTwo, 46 }) 47 c.Assert(err, jc.ErrorIsNil) 48 unitTwo, err := appTwo.AddUnit(state.AddUnitParams{}) 49 c.Assert(err, jc.ErrorIsNil) 50 unitTwo.SetCharmURL(charmTwo.URL()) 51 52 runCommandExpectSuccess(c, "add-relation", s.appOneName, s.appTwoName) 53 } 54 55 // This test deploys 2 applications with 1 unit each and relates units to each other. 56 // It then updates charm for one of the application with various changes to relations. 57 // All upgrades should succeed since there is only one unit. 58 // The only update that should fail is with changes to relation 59 // that has already been established to another application's unit. 60 // Addresses lp#1510787 scenario. 61 func (s *CharmUpgradeSuite) TestUpgradeCharm(c *gc.C) { 62 // should pass: peer relation name to one unit changed 63 v2 := s.AddTestingCharm(c, "upgrade-charm1v2") 64 cfg := state.SetCharmConfig{Charm: v2} 65 err := s.appOne.SetCharm(cfg) 66 c.Assert(err, jc.ErrorIsNil) 67 68 // should pass: peer relation interface name to one unit changed 69 v3 := s.AddTestingCharm(c, "upgrade-charm1v3") 70 cfg = state.SetCharmConfig{Charm: v3} 71 err = s.appOne.SetCharm(cfg) 72 c.Assert(err, jc.ErrorIsNil) 73 74 // should fail: peer relation change to another app's unit exist 75 v4 := s.AddTestingCharm(c, "upgrade-charm1v4") 76 cfg = state.SetCharmConfig{Charm: v4} 77 err = s.appOne.SetCharm(cfg) 78 c.Assert(err, gc.ErrorMatches, fmt.Sprintf(`*would break relation "%v:server %v:server"*`, s.appTwoName, s.appOneName)) 79 }