github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/updater/util/etag_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 TestEtag(t *testing.T) { 13 data := []byte("test data\n") 14 path, err := WriteTempFile("TestEtag", data, 0644) 15 assert.NoError(t, err) 16 defer RemoveFileAtPath(path) 17 18 etag, err := ComputeEtag(path) 19 assert.NoError(t, err) 20 assert.Equal(t, "39a870a194a787550b6b5d1f49629236", etag) 21 } 22 23 func TestEtagNoData(t *testing.T) { 24 var data []byte 25 path, err := WriteTempFile("TestEtag", data, 0644) 26 assert.NoError(t, err) 27 defer RemoveFileAtPath(path) 28 29 etag, err := ComputeEtag(path) 30 assert.NoError(t, err) 31 assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", etag) 32 } 33 34 func TestEtagInvalidPath(t *testing.T) { 35 etag, err := ComputeEtag("/tmp/invalidpath") 36 t.Logf("Error: %#v", err) 37 assert.Error(t, err) 38 assert.Equal(t, "", etag) 39 }