github.com/release-engineering/exodus-rsync@v1.11.2/internal/gw/client_encode_error_test.go (about)

     1  package gw
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  // Verify we get an error if doJSONRequest is used with something non-JSON-encodable.
    10  func TestClientEncodeError(t *testing.T) {
    11  	// This case can't be triggered using the client public API, so we just invoke this
    12  	// lower level method on an instance directly.
    13  	client := client{}
    14  
    15  	// This could be any unmarshallable object
    16  	x := func() {}
    17  
    18  	err := client.doJSONRequest(context.TODO(), "POST", "https://example.com/", x, nil, nil)
    19  	if err == nil {
    20  		t.Error("unexpectedly did not fail")
    21  	}
    22  
    23  	if !strings.Contains(err.Error(), "unsupported type") {
    24  		t.Errorf("Did not get expected error, got: %v", err)
    25  	}
    26  }