Skip to content

Replace gopkg.in/check.v1 with the standard testing library #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 7, 2025

Conversation

carloslima
Copy link
Contributor

closes #21

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 18:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the dependency on gopkg.in/check.v1 and converts all existing test suites to use Go’s standard testing package, preserving test logic and adding subtests or reflect.DeepEqual/regexp‐based assertions.

  • Deleted the legacy suite_test.go and go-check suite boilerplate.
  • Updated multiple *_test.go files to replace GoCheck assertions with testing.T methods and reflect.DeepEqual/regexp checks.
  • Cleaned up go.mod by removing the GoCheck requirement.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
suite_test.go Removed GoCheck suite setup (no longer needed).
node_test.go Converted node tests to use testing.T, reflect.DeepEqual, regexp.
limit_test.go Switched limit tests to testing.T and regexp, removed GoCheck.
encode_test.go Migrated encoding tests to testing.T, added subtests.
decode_test.go Migrated decoding tests to testing.T, added subtests.
go.mod Removed gopkg.in/check.v1 from module requirements.
Comments suppressed due to low confidence (4)

encode_test.go:515

  • The fmt.Sprintf call is used here but fmt is not imported; add import "fmt" to the import block.
		t.Run(fmt.Sprintf("test %d: %q", i, item.data), func(t *testing.T) {

decode_test.go:870

  • The fmt.Sprintf call is used here but fmt is not imported; add import "fmt" to the import block.
		t.Run(fmt.Sprintf("test %d: %q", i, item.data), func(t *testing.T) {

decode_test.go:1954

  • bytes.NewBuffer is used here but bytes is not imported; add import "bytes" to the import block.
		dec := yaml.NewDecoder(bytes.NewBuffer([]byte(item.data)))

limit_test.go:43

  • [nitpick] Instead of return to skip short tests, call t.Skip("skipping long test in short mode") so the test is marked as skipped.
}

Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I raised a few things, but LGTM 👍

Thanks for working on this

@andig
Copy link

andig commented Jul 6, 2025

That's why the whole thing felt so odd. I've also made good experience with github.com/stretchr/testify to complement testing. This pattern

	if err != nil {
		t.Fatalf("Close() returned error: %v", err)
	}

then becomes

    require.NoError(t, err, "Close() returned error: %v", err)

or simply

    require.NoError(t, err, "Close() returned error")

@ccoVeille
Copy link
Contributor

ccoVeille commented Jul 6, 2025

@andig I'm unsure what you meant.

The way it sounds to me is "okay, but it was simpler with testify and I'm used to it."

While I agree, it doesn't sound logic to me.

Dolmen and @brackendawson testify maintainers asked yaml project to do not depends on testify because testify depends itself on (the old) yaml project. The idea is to avoid cyclic dependencies.

So testify cannot be used.

Here I don't see a problem with this PR. A few files are updated, yes, it's not as simple as testify, yes, it is using vanilla testing.

But I would say it's expected because:

  • it was what was asked the issue
  • it is what this PR is about.

If there is a huge problem, nothing prevents to add a internal wrapper library that could check:

  • for error
  • if error is equal to another (using errors.Is)
  • if error contains a string

And report test failure message returning the expected state.

It's easy. It can be extended if needed.

But this would be a NIH logic,
an/or at real choice of reducing the number of dependencies.

BTW Bracken suggested to use is which has no dependencies. It could be considered.

#21 (comment)

I feel like having a few wrappers could be considered, if vanilla become a problem.

This is the reply I'm doing about what I understood you say. But as I said, I might have misunderstood what you meant. So please apologize myself if I'm wrong and my reply is pointless.

@andig
Copy link

andig commented Jul 6, 2025

The idea is to avoid cyclic dependencies.

Sorry, I wasn‘t aware of that. I‘m confused by how that would be a bad thing for tests, but that‘s OT. No concerns, sorry for the noise.

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

PS. We should be using t.Setenv but this can come later in a different PR.

@ingydotnet
Copy link
Member

This looks good enough to merge.

We can apply the optimization ideas in further PRs.

@ingydotnet ingydotnet merged commit bc5dce3 into yaml:main Jul 7, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor tests to use vanilla testing package plus github.com/stretchr/testify
5 participants