github.com/jbendotnet/noms@v0.0.0-20190904222105-c43e4293ea92/go/util/test/equals_ignore_hashes.go (about)

     1  // Copyright 2016 Attic Labs, Inc. All rights reserved.
     2  // Licensed under the Apache License, version 2.0:
     3  // http://www.apache.org/licenses/LICENSE-2.0
     4  
     5  package test
     6  
     7  import (
     8  	"regexp"
     9  	"strconv"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/attic-labs/noms/go/hash"
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  var pattern = regexp.MustCompile("([0-9a-v]{" + strconv.Itoa(hash.StringLen) + "})")
    18  
    19  // EqualsIgnoreHashes compares two strings, ignoring hashes in them.
    20  func EqualsIgnoreHashes(tt *testing.T, expected, actual string) {
    21  	if RemoveHashes(expected) != RemoveHashes(actual) {
    22  		assert.Equal(tt, expected, actual)
    23  	}
    24  }
    25  
    26  func RemoveHashes(str string) string {
    27  	return pattern.ReplaceAllString(str, strings.Repeat("*", hash.StringLen))
    28  }