Skip to content
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

assert: make YAML dependency pluggable via build tags #1579

Merged
merged 1 commit into from May 23, 2024

Commits on Mar 31, 2024

  1. assert: make YAML dependency pluggable via build tags

    Make the YAML dependency required for {assert,require}.YAMLEq{,f} pluggable.
    
    The implementation can be selected using build tags:
    - testify_yaml_default (default): gopkg.in/yaml.v3 is used, like before
    - testify_yaml_fail: YAML deserialization is not implemented and always
      fails. So assert.YAMLEq always fails. This is useful if the test suite
      package doesn't use assert.YAMLEq (very common case).
    - testify_yaml_custom: the github.com/stretchr/testify/assert/yaml
      package exposes an Unmarshal variable of type func([]byte, any) error
      (same as gopkg.in/yaml.v3) that allows to plug any alternate
      implementation. For example github.com/goccy/go-yaml.Unmarshal.
      This allows to avoid the link constraints of the license of
      gopkg.in/yaml.v3 (see PR #1120).
    
    Usage: go test -tags testify_yaml_fail
    
    To install the alternate implementation with testify_yaml_custom:
    
    	//go:build testify_yaml_custom
    
    	package my_pkg_test
    
    	import (
    		goyaml "github.com/goccy/go-yaml"
    		"github.com/stretchr/testify/assert/yaml"
    	)
    
    	func init() {
    		yaml.Unmarshal = goyaml.Unmarshal
    	}
    dolmen committed Mar 31, 2024
    Configuration menu
    Copy the full SHA
    d3dbb19 View commit details
    Browse the repository at this point in the history