Skip to content
Snippets Groups Projects
libvirt_test.go 769 B
Newer Older
  • Learn to ignore specific revisions
  • Lars Seipel's avatar
    Lars Seipel committed
    package libvirt
    
    import (
    	"bytes"
    	"testing"
    	"text/template"
    
    	"slrz.net/runtopo/topology"
    )
    
    func TestValidDomainXML(t *testing.T) {
    	topo, err := topology.ParseFile("testdata/leafspine.dot", topology.WithAutoMgmtNetwork)
    	if err != nil {
    		t.Fatal(err)
    	}
    
    	r := NewRunner()
    	if err := r.buildInventory(topo); err != nil {
    		t.Fatal(err)
    	}
    
    	tmpl, err := template.New("").
    		Funcs(templateFuncs).
    		Parse(domainTemplateText)
    	if err != nil {
    		t.Fatal(err)
    	}
    
    	var buf bytes.Buffer
    	for _, d := range r.devices {
    		if err := tmpl.Execute(&buf, d.templateArgs()); err != nil {
    
    			t.Errorf("domain %s: %v", d.name, err)
    
    Lars Seipel's avatar
    Lars Seipel committed
    		}
    		domXML := buf.Bytes()
    		if err := validateDomainXML(domXML); err != nil {
    
    			t.Errorf("domain %s: %v", d.name, err)
    
    Lars Seipel's avatar
    Lars Seipel committed
    		}
    		buf.Reset()
    	}
    }