testify icon indicating copy to clipboard operation
testify copied to clipboard

Add `NotImplements` and variants

Open hslatman opened this issue 2 years ago โ€ข 3 comments

Summary

Add assert.NotImplements (and variants)

Changes

Added assert.NotImplements (and variants)

Motivation

There was no way to test an object did not implement a specific interface yet. Its counterpart does exist, so it was somewhat surprising to not be able to test the inverse.

import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	
	"github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
)


func Test_NotASigner(t *testing.T) {
	e, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
        require.NoError(t, err)
        assert.NotImplements(t, (*crypto.Signer)(nil), e.Public()) // public key only isn't a signer
}

Related issues

Closes #1065

hslatman avatar May 22 '23 21:05 hslatman

@CodiumAI-Agent please review

coditamar avatar Jul 06 '23 13:07 coditamar

PR Analysis

  • ๐ŸŽฏ Main theme: Adding a new assertion method
  • ๐Ÿ” Description and title: Yes
  • ๐Ÿ“Œ Type of PR: Enhancement
  • ๐Ÿงช Relevant tests added: Yes
  • โœจ Minimal and focused: Yes, because the PR is focused on adding a new assertion method and all changes are relevant to this addition.
  • ๐Ÿ”’ Security concerns: No, because the PR is focused on adding a new assertion method and does not involve any security-sensitive operations.

PR Feedback

  • ๐Ÿ’ก General PR suggestions: The PR is well-structured and follows the existing code style. The new method is added in all the necessary places and the tests cover the main use cases.

How to use

Tag me in a comment '@CodiumAI-Agent' to ask for a new review after you update the PR. You can also tag me and ask any question, for example '@CodiumAI-Agent is the PR ready for merge?'

QodoAI-Agent avatar Jul 06 '23 13:07 QodoAI-Agent

Patch is good.

However I'm not sure we want to extend the API. At least the must wait for 1.9.0.

dolmen avatar Oct 16 '23 12:10 dolmen