Skip to content

Incorrect tests caused to the wrong solutions for challenge-12 #488

@nzamulov

Description

@nzamulov

There are 2 incorrect tests in the challenge: Transformation error and Writer error.

Let's take a look at the first one. We should make an attention on mock transformer creation:

transformer := NewMockTransformer(inputData, nil, &TransformError{Stage: "uppercase", Err: errors.New("transform error")})

And we should make an attention on the .Transform() method of the NewMockTransformer instance:

func (mt *MockTransformer) Transform(data []byte) ([]byte, error) {
	mt.transforms++

	if reflect.DeepEqual(data, mt.input) {
		return mt.output, nil
	}

	return nil, mt.err
}

So, in the Transform() method we do data comparison first and return an error second. If data matches with input we return mt.output and does not even matter error was setup or not. As seen above, transformer created with initial inputData and this means that if reflect.DeepEqual(data, mt.input) will be true and error will not be returned. At the same time, in the test we are checking that an error is returning and it has needed "type" (more strongly, it is looking for needed substring into the error):

if !strings.Contains(err.Error(), "transform") {
	t.Errorf("Error should contain transform info, got: %v", err)
}

So, it's not valid transform logic. Common assumption that transform makes some doings and returning valid output or returning an error if it was occurred during those transformation itself. Based on this assumption we need to check mt.err before data comparison and return it if it was actually setup.

If we look at the submissions of other guys who successfully solved the problem we will see that all of them do some "sidecar-staff" that going to allow pass all tests but has nothing with correct solution for original problem:

  1. Cpoing checks that data is nil and returns custom error with transform error text just for correct comparison with word "transform" that was mentioned above. He did not return an original error TransformError that was passed in time of creation of NewMockTransformer.
  2. odelbos doing the same things.
  3. longbui98 also doing the same things too.

With Writer error test we have the same problem. Actually, it is more funny when in the pipeline logic guys want to write nil value at the final step instead of correct value ([]byte): 1, 2 and 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions