github.com/tiagovtristao/plz@v13.4.0+incompatible/src/hashes/hash_rewriter_test.go (about)

     1  package hashes
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/thought-machine/please/src/core"
    12  	"github.com/thought-machine/please/src/fs"
    13  )
    14  
    15  func TestRewriteHashes(t *testing.T) {
    16  	state := core.NewDefaultBuildState()
    17  	// Copy file to avoid any issues with links etc.
    18  	wd, _ := os.Getwd()
    19  	err := fs.CopyFile("src/hashes/test_data/before.build", path.Join(wd, "test.build"), 0644)
    20  	assert.NoError(t, err)
    21  	assert.NoError(t, rewriteHashes(state, "test.build", "test_x86", map[string]string{
    22  		"test1": "b9643f8154a9e9912d730a931d329afc82a44a52",
    23  		"test2": "bd79dd61c1494072271f3d13350ccbc26c25a09e",
    24  		"test3": "94ead0b0422cad925910e5f8b6f9bd93b309f8f0",
    25  		"test4": "ab2649b7e58f7e32b0c75be95d11e2979399d392",
    26  	}))
    27  	rewritten, err := ioutil.ReadFile("test.build")
    28  	assert.NoError(t, err)
    29  	after, err := ioutil.ReadFile("src/hashes/test_data/after.build")
    30  	assert.NoError(t, err)
    31  	assert.EqualValues(t, string(after), string(rewritten))
    32  }