-3

My tests are failing due to a 3rd party error that is irrelevant to the tests themselves. Basically some testserver I have to use fails to shutdown on Windows OS but actually runs fine.

I need to ignore the errors it generates, but they are in the defer part as below. Is there a way to completely ignore any errors coming from the first two lines?

func TestDoSomething(t *testing.T) {
    testServer := setupTestNomad(t) //contains 3rd party test server creation
    defer testServer.Stop()  //actually fails here in the 3rd party struct due to 3rd party code itself

    data := DoSomething()
    if data == nil { //data is not null and all is fine here
        t.Errorf("Failed, data null")
    }
}

Test dies because of this within their code

enter image description here

mechanicum
  • 699
  • 3
  • 14
  • 25
  • 1
    Go test runs the tests you tell it to; it has no notion of "third party tests". `TestDoSomething` is a test of whatever package it is defined in. – Adrian Feb 17 '22 at 17:34
  • So moving the server creation and stop outside should help in that case. thanks. – mechanicum Feb 17 '22 at 17:38

2 Answers2

1

Is there a way to ignore test errors coming from third party packages during unit tests?

No, not in your case because the test is not "from third party package": The test is yours and it fails. The fact that your code calls a function from a "third party package" has no meaning here.

Volker
  • 40,468
  • 7
  • 81
  • 87
  • the function of the third party package throwing the error in the image is the problem though. I just wrapped for easier use. Should I have been using the 3rd party function directly? – mechanicum Feb 17 '22 at 17:27
  • @mechanicum you should call the third party function correctly, so that it doesn't error. – The Fool Feb 17 '22 at 17:30
  • I am calling it correctly. the defer testServer.Stop() fails because I'm using windows. Within the stop method of the 3rd party the part in the image fails the outside test itself since it cannot complete the interrupt command. Nothing related with the test I have. – mechanicum Feb 17 '22 at 17:33
0

Moving it to another namespace didn't help nor did the above helpful comments.

The testing.T struct I carry around and use to create a new Nomad Test server allows the 3rd party code to fail my test. Not using that and using a new object as below solves this problem.

nomadTestUtil.NewTestServer(&testing.T{},...
mechanicum
  • 699
  • 3
  • 14
  • 25