newman: Unexpected end of file at request

I created one hyper simple collection. A single call with this in the Tests:

var token = postman.getResponseHeader("Authorization");
postman.setEnvironmentVariable("token", token);

tests["Successfully authenticated"] = token !== null;

In the GUI, it runs successfully. Running with newman, it does show a checkmark next to the “Successfully authenticated” test, but there’s still an [errored] which I imagine is because of the unexpected end of file at request. I’m running node v5.7.1 and newman v3.1.2

I’m not sure if this is related to https://github.com/postmanlabs/newman/issues/319 or not.

> newman run Compas_REST_Case_Tests.postman_collection.json -e Compas8_Blank.postman_environment.json
newman

Compas_REST_Case_Tests

→ Authenticate
  POST http://localhost/Foo/api/authentication [errored]
  √  Successfully authenticated

┌─────────────────────────┬──────────┬──────────┐
│                         │ executed │   failed │
├─────────────────────────┼──────────┼──────────┤
│              iterations │        1 │        0 │
├─────────────────────────┼──────────┼──────────┤
│                requests │        1 │        1 │
├─────────────────────────┼──────────┼──────────┤
│            test-scripts │        1 │        0 │
├─────────────────────────┼──────────┼──────────┤
│      prerequest-scripts │        0 │        0 │
├─────────────────────────┼──────────┼──────────┤
│              assertions │        1 │        0 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 986ms                     │
├───────────────────────────────────────────────┤
│ total data received: 0B (approx)              │
├───────────────────────────────────────────────┤
│ average response time: 0ms                    │
└───────────────────────────────────────────────┘

  #  failure  detail

 1.  Error    unexpected end of file
              at request
              inside "Authenticate" of "Compas_REST_Case_Tests"

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (16 by maintainers)

Most upvoted comments

Well, I fixed it. I’m not sure if this is considered a bug or what, but (I’ll share heavily heavily reduced code):

Like I said, the HttpResponse was lacking any body content, and was just sending back header data.

So, I went from:

public HttpResponseMessage Post(LoginModel data)
{
    var response = Request.CreateResponse(HttpStatusCode.Created);
    response.Headers.Add("Foo", "Bar " + token.Value);
    return response;
}

to this:

public HttpResponseMessage Post(LoginModel data)
{
    var response = Request.CreateResponse(HttpStatusCode.Created);
    response.Headers.Add("Foo", "Bar " + token.Value);
    response.Content = new StringContent(Json.Encode(new Dictionary<string, dynamic> {{"Name", "Jared"}}));
    return response;
}

And all is well!

> newman run STASH.postman_collection.json -e Compas8_Blank.postman_environment.json
newman

STASH

→ Authenticate
  POST http://localhost:80/Compas/api/authentication [201 Created, 809B, 59ms]
  √  Successfully authenticated

→ GetPerson
  GET http://localhost:80/Foo?bar=baz [200 OK, 725B, 25ms]
  √ ID is correct

┌─────────────────────────┬──────────┬──────────┐
│                         │ executed │   failed │
├─────────────────────────┼──────────┼──────────┤
│              iterations │        1 │        0 │
├─────────────────────────┼──────────┼──────────┤
│                requests │        2 │        0 │
├─────────────────────────┼──────────┼──────────┤
│            test-scripts │        2 │        0 │
├─────────────────────────┼──────────┼──────────┤
│      prerequest-scripts │        0 │        0 │
├─────────────────────────┼──────────┼──────────┤
│              assertions │        2 │        0 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 1274ms                    │
├───────────────────────────────────────────────┤
│ total data received: 488B (approx)            │
├───────────────────────────────────────────────┤
│ average response time: 42ms                   │
└───────────────────────────────────────────────┘