~jameinel/goose/break-juju

« back to all changes in this revision

Viewing changes to tools/secgroup-delete-all/main_test.go

  • Committer: Tarmac
  • Author(s): Ian Booth
  • Date: 2013-02-22 00:50:14 UTC
  • mfrom: (72.3.4 auto-reauth)
  • Revision ID: tarmac-20130222005014-ywhhes5rf5v5paub
[r=wallyworld] Try and re-authorise automatically

If a request returns 401 or 403, attempt to re-authorise and then retry the request.
The service double hook code was moved to a new package so that some tests could be
written without circular import issues.

https://codereview.appspot.com/7374044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "launchpad.net/goose/identity"
9
9
        "launchpad.net/goose/nova"
10
10
        "launchpad.net/goose/testing/httpsuite"
11
 
        "launchpad.net/goose/testservices"
 
11
        "launchpad.net/goose/testservices/hook"
12
12
        "launchpad.net/goose/testservices/openstackservice"
13
13
        tool "launchpad.net/goose/tools/secgroup-delete-all"
14
14
        "testing"
60
60
}
61
61
 
62
62
func (s *ToolSuite) TestTwoGroups(c *C) {
63
 
        _, nova := s.makeServices(c)
64
 
        nova.CreateSecurityGroup("group-a", "A group")
65
 
        nova.CreateSecurityGroup("group-b", "Another group")
 
63
        _, novaClient := s.makeServices(c)
 
64
        novaClient.CreateSecurityGroup("group-a", "A group")
 
65
        novaClient.CreateSecurityGroup("group-b", "Another group")
66
66
        var buf bytes.Buffer
67
 
        err := tool.DeleteAll(&buf, nova)
 
67
        err := tool.DeleteAll(&buf, novaClient)
68
68
        c.Assert(err, IsNil)
69
69
        c.Assert(string(buf.Bytes()), Equals, "2 security groups deleted.\n")
70
70
}
73
73
var doNotDelete *nova.SecurityGroup
74
74
 
75
75
// deleteGroupError hook raises an error if a group with id 2 is deleted.
76
 
func deleteGroupError(s testservices.ServiceControl, args ...interface{}) error {
 
76
func deleteGroupError(s hook.ServiceControl, args ...interface{}) error {
77
77
        groupId := args[0].(int)
78
78
        if groupId == doNotDelete.Id {
79
79
                return fmt.Errorf("cannot delete group %d", groupId)
82
82
}
83
83
 
84
84
func (s *ToolSuite) TestUndeleteableGroup(c *C) {
85
 
        os, nova := s.makeServices(c)
86
 
        nova.CreateSecurityGroup("group-a", "A group")
87
 
        doNotDelete, _ = nova.CreateSecurityGroup("group-b", "Another group")
88
 
        nova.CreateSecurityGroup("group-c", "Yet another group")
 
85
        os, novaClient := s.makeServices(c)
 
86
        novaClient.CreateSecurityGroup("group-a", "A group")
 
87
        doNotDelete, _ = novaClient.CreateSecurityGroup("group-b", "Another group")
 
88
        novaClient.CreateSecurityGroup("group-c", "Yet another group")
89
89
        cleanup := os.Nova.RegisterControlPoint("removeSecurityGroup", deleteGroupError)
90
90
        defer cleanup()
91
91
        var buf bytes.Buffer
92
 
        err := tool.DeleteAll(&buf, nova)
 
92
        err := tool.DeleteAll(&buf, novaClient)
93
93
        c.Assert(err, IsNil)
94
94
        c.Assert(string(buf.Bytes()), Equals, "2 security groups deleted.\n1 security groups could not be deleted.\n")
95
95
}