github.com/angryronald/go-kit@v0.0.0-20240505173814-ff2bd9c79dbf/generic/http/client/clienttest/error.model_test.go (about)

     1  package clienttest
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/angryronald/go-kit/generic/http/client"
     8  )
     9  
    10  func TestResponseError_FromError(t *testing.T) {
    11  	// Create an error to be used as input to the method
    12  	expectedError := errors.New("example error")
    13  
    14  	// Create a ResponseError instance
    15  	var responseError client.ResponseError
    16  
    17  	// Call the FromError method with the error
    18  	responseError.FromError(expectedError)
    19  
    20  	// Check if the ResponseError's Error field contains the same error
    21  	if responseError.Error != expectedError {
    22  		t.Errorf("Expected error %v, but got %v", expectedError, responseError.Error)
    23  	}
    24  
    25  	// You can add more assertions as needed for other fields of ResponseError
    26  	if responseError.Code != "" || responseError.Message != "" || responseError.StatusCode != 0 || responseError.Info != "" {
    27  		t.Errorf("Unexpected values in ResponseError fields")
    28  	}
    29  }