github.com/vmware/govmomi@v0.51.0/vim25/soap/soap_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package soap
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/vmware/govmomi/vim25/xml"
    11  )
    12  
    13  func TestEmptyEnvelope(t *testing.T) {
    14  	env := Envelope{}
    15  
    16  	b, err := xml.Marshal(env)
    17  	if err != nil {
    18  		t.Errorf("error: %s", err)
    19  		return
    20  	}
    21  
    22  	expected := `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"></Envelope>`
    23  	actual := string(b)
    24  	if expected != actual {
    25  		t.Fatalf("expected: %s, actual: %s", expected, actual)
    26  	}
    27  }
    28  
    29  func TestNonEmptyHeader(t *testing.T) {
    30  	env := Envelope{
    31  		Header: &Header{
    32  			ID: "foo",
    33  		},
    34  	}
    35  
    36  	b, err := xml.Marshal(env)
    37  	if err != nil {
    38  		t.Errorf("error: %s", err)
    39  		return
    40  	}
    41  
    42  	env = Envelope{}
    43  	err = xml.Unmarshal(b, &env)
    44  	if err != nil {
    45  		t.Errorf("error: %s", err)
    46  	}
    47  
    48  	if env.Header.ID != "foo" {
    49  		t.Errorf("ID=%s", env.Header.ID)
    50  	}
    51  }