github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/updater/util/digest_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package util
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestDigest(t *testing.T) {
    13  	data := []byte("test data\n")
    14  	path, err := WriteTempFile("TestDigest", data, 0644)
    15  	assert.NoError(t, err)
    16  	defer RemoveFileAtPath(path)
    17  
    18  	err = CheckDigest("0c15e883dee85bb2f3540a47ec58f617a2547117f9096417ba5422268029f501", path, testLog)
    19  	assert.NoError(t, err)
    20  
    21  	err = CheckDigest("bad", path, testLog)
    22  	assert.Error(t, err)
    23  
    24  	err = CheckDigest("", path, testLog)
    25  	assert.Error(t, err)
    26  }
    27  
    28  func TestDigestInvalidPath(t *testing.T) {
    29  	err := CheckDigest("0c15e883dee85bb2f3540a47ec58f617a2547117f9096417ba5422268029f501", "/tmp/invalidpath", testLog)
    30  	t.Logf("Error: %#v", err)
    31  	assert.Error(t, err)
    32  }