github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetalintrospection/v1/introspection/testing/results_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"encoding/json"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  )
    11  
    12  func TestLLDPTLVErrors(t *testing.T) {
    13  	badInputs := []string{
    14  		"[1]",
    15  		"[1, 2]",
    16  		"[\"foo\", \"bar\"]",
    17  	}
    18  
    19  	for _, input := range badInputs {
    20  		var output introspection.LLDPTLVType
    21  		err := json.Unmarshal([]byte(input), &output)
    22  		if err == nil {
    23  			t.Fatalf("No JSON parse error for invalid LLDP TLV %s", input)
    24  		}
    25  
    26  		if !strings.Contains(err.Error(), "LLDP TLV") {
    27  			t.Fatalf("Unexpected JSON parse error \"%s\" for invalid LLDP TLV %s", err, input)
    28  		}
    29  	}
    30  }
    31  
    32  func TestExtraHardware(t *testing.T) {
    33  	var output introspection.ExtraHardwareDataType
    34  	err := json.Unmarshal([]byte(IntrospectionExtraHardwareJSONSample), &output)
    35  	if err != nil {
    36  		t.Fatalf("Failed to unmarshal ExtraHardware data: %s", err)
    37  	}
    38  
    39  	th.CheckDeepEquals(t, IntrospectionExtraHardware, output)
    40  }
    41  
    42  func TestIntrospectionNUMA(t *testing.T) {
    43  	var output introspection.Data
    44  	err := json.Unmarshal([]byte(IntrospectionNUMADataJSONSample), &output)
    45  	if err != nil {
    46  		t.Fatalf("Failed to unmarshal NUMA Data: %s", err)
    47  	}
    48  
    49  	th.CheckDeepEquals(t, IntrospectionNUMA, output.NUMATopology)
    50  }
    51  
    52  func TestHostnameInInventory(t *testing.T) {
    53  	var output introspection.Data
    54  	err := json.Unmarshal([]byte(IntrospectionDataJSONSample), &output)
    55  	if err != nil {
    56  		t.Fatalf("Failed to unmarshal Inventory data: %s", err)
    57  	}
    58  
    59  	th.CheckDeepEquals(t, IntrospectionDataRes.Inventory.Hostname, "myawesomehost")
    60  }