github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/state/backups/testing/testing.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"crypto/sha1"
     8  	"encoding/base64"
     9  	"io"
    10  	"os"
    11  
    12  	jc "github.com/juju/testing/checkers"
    13  	gc "gopkg.in/check.v1"
    14  )
    15  
    16  // SHA1SumFile returns the RFC 3230 SHA hash of the file.
    17  func SHA1SumFile(c *gc.C, file *os.File) string {
    18  	shahash := sha1.New()
    19  	_, err := io.Copy(shahash, file)
    20  	c.Assert(err, jc.ErrorIsNil)
    21  	return base64.StdEncoding.EncodeToString(shahash.Sum(nil))
    22  }