Commit b9456add authored by Daniel P. Berrange's avatar Daniel P. Berrange

Fix ability to clear metadata

We need to turn "" into NULL when calling virDomainSetMetadata
to ensure it can be cleared
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 33d17679
......@@ -1281,12 +1281,16 @@ func (d *Domain) SetMetadata(metaDataType DomainMetadataType, metaDataCont, uriK
var cUriKey *C.char
var cUri *C.char
cMetaDataCont = C.CString(metaDataCont)
defer C.free(unsafe.Pointer(cMetaDataCont))
if metaDataCont != "" {
cMetaDataCont = C.CString(metaDataCont)
defer C.free(unsafe.Pointer(cMetaDataCont))
}
if metaDataType == DOMAIN_METADATA_ELEMENT {
cUriKey = C.CString(uriKey)
defer C.free(unsafe.Pointer(cUriKey))
if uriKey != "" {
cUriKey = C.CString(uriKey)
defer C.free(unsafe.Pointer(cUriKey))
}
cUri = C.CString(uri)
defer C.free(unsafe.Pointer(cUri))
}
......
......@@ -816,3 +816,53 @@ func TestParserCPUString(t *testing.T) {
}
}
}
func TestSetMetadata(t *testing.T) {
xmlns := "http://libvirt.org/xmlns/libvirt-go/test"
xmlprefix := "test"
meta := "<blob/>"
dom, conn := buildTestDomain()
defer func() {
dom.Free()
if res, _ := conn.Close(); res != 0 {
t.Errorf("Close() == %d, expected 0", res)
}
}()
data, err := dom.GetMetadata(DOMAIN_METADATA_ELEMENT, xmlns, 0)
if err == nil {
t.Errorf("Expected an error for missing metadata")
return
}
err = dom.SetMetadata(DOMAIN_METADATA_ELEMENT, meta, xmlprefix, xmlns, 0)
if err != nil {
t.Error(err)
return
}
data, err = dom.GetMetadata(DOMAIN_METADATA_ELEMENT, xmlns, 0)
if err != nil {
t.Errorf("Unexpected an error for metadata")
return
}
if data != meta {
t.Errorf("Metadata %s doesn't match %s", data, meta)
return
}
err = dom.SetMetadata(DOMAIN_METADATA_ELEMENT, "", "", xmlns, 0)
if err != nil {
t.Error(err)
return
}
data, err = dom.GetMetadata(DOMAIN_METADATA_ELEMENT, xmlns, 0)
if err == nil {
t.Errorf("Expected an error for deleted metadata")
return
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment