Merge lp://staging/~julian-edwards/gwacl/xml-definitions into lp://staging/gwacl
Status: | Merged |
---|---|
Approved by: | Julian Edwards |
Approved revision: | 17 |
Merged at revision: | 6 |
Proposed branch: | lp://staging/~julian-edwards/gwacl/xml-definitions |
Merge into: | lp://staging/gwacl |
Diff against target: |
574 lines (+554/-0) 3 files modified
test_helpers.go (+178/-0) xmlobjects.go (+156/-0) xmlobjects_test.go (+220/-0) |
To merge this branch: | bzr merge lp://staging/~julian-edwards/gwacl/xml-definitions |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Julian Edwards (community) | Approve | ||
Review via email:
|
Commit message
Add enough xml object declarations to be able to compose a Deployment message for a Linux VM.
Description of the change
Add a bunch of xml object declarations - just enough to compose a Deployment message for the Azure API.
Points of interest:
* I don't know if the "done thing" is to have a struct parameter so I can have nil args, but there it is anyway. It's needed to make the factory funcs useful.
* You can't have a common class method that's composed into the various objects (or put one on an interface) because the receiver would be wrong. Hence I factored as much as I could into the toxml() method and then added Serialize() receivers on the various object structs. I am open to suggestions if there's a better way.
* Go doesn't have a dedent, so the multiline test strings all start at column zero :(
Please consider the suggestions I have; apart from what I point out in [7] nothing is really *wrong* but I think we can improve things a bit:
[0]
Please use 'gofmt' to reformat the code. The structures with their "xml decorations" will be much more readable.
[1]
21 +func makeEndpoint(params endpointParams) *InputEndpoint { ioningConfigura tion(params provconfParams) *LinuxProvision ingConfiguratio n {
[...]
40 +func makeLinuxProvis
etc.
It's a detail but in Go, creator methods like this tend to use the 'New' prefix (instead of make); the typical declaration is: "NewT() *T". I know it does not matter much but it's good to follow the Go standards whenever it does not hurt.
[2]
149 +// It's impossible to have any kind of common method inherited into all the nt(obj, "", " ")
150 +// various serializable objects because the receiver of the method is the
151 +// wrong class which confuses the xml marshaller. Hence, this mess.
152 +type AzureObject interface {
153 + Serialize() (string, error)
154 +}
155 +
156 +func toxml(obj AzureObject) (string, error) {
157 + out, err := xml.MarshalInde
158 + if err != nil {
159 + return "", err
160 + }
161 + return string(out), nil
162 +}
[...]
183 +func (c *InputEndpoint) Serialize() (string, error) {
184 + return toxml(c)
185 +}
You said you wanted to do this in order to have a Serialize() method on each object instead of having to call a global method. I agree with you in principle but here that it would be better. However, in Go, what you had to do in order to do this is add some boilerplate code that simply limits our ability to control how the xml is produced (by wrapping it in a method that does basically nothing but call xml.MarshalInde nt()). I'll leave it up to you because you seemed to have very strong feelings about this but I'd advise getting rid of this completely and simply using xml.MarshalIndent() in the tests.
[3]
259 + c.Check(xml, Equals, fmt.Sprintf(` ningConfigurati on> etType> LinuxProvisioni ngConfiguration </Configuration SetType>
260 +<LinuxProvisio
261 + <ConfigurationS
If Gavin can write a Dedent() method, the definition of the expected XML in the tests will look much better.
[4]
205 +type Role struct { ningConfigurati on `xml:"Configura tionSets> ConfigurationSe t"`
206 + RoleSize string `xml:"RoleSize"`
207 + RoleName string `xml:"RoleName"`
208 + RoleType string `xml:"RoleType"` // Always "PersistentVMRole"
209 + ConfigurationSet []LinuxProvisio
210 +}
There is no support for default values of a field in a structure and this is a PITA. But I suggest creating a method with the following signature: "NewRole(roleSize string, roleName string, configurationSet []LinuxProvisio ningConfigurati on)" that will initialize the new struct's 'roleType' field with "PersistentVMRole".
Same for the other structures that have constant fields. I know that creating this code, for python programmers, seems like wasted time but AFAIK this is the only way to do this in Go and this way, you encapsulate that knowledge in the code and can test for it, instead of expecting the caller to do the right thing based on a comment in the code.
[5]
134 func init() {
...