提交 5206a111 作者: Lars Gierth

godeps: remove unused github.com/mtchavez/jenkins

License: MIT
Signed-off-by: 's avatarLars Gierth <larsg@systemli.org>
上级 5146b34a
......@@ -50,10 +50,6 @@
"Rev": "1f6da4a72e57d4e7edd4a7295a585e0a3999a2d4"
},
{
"ImportPath": "github.com/mtchavez/jenkins",
"Rev": "5a816af6ef21ef401bff5e4b7dd255d63400f497"
},
{
"ImportPath": "github.com/syndtr/gosnappy/snappy",
"Rev": "156a073208e131d7d2e212cb749feae7c339e846"
},
......
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
go:
- 1.1
- tip
install:
- go get github.com/onsi/ginkgo
- go get github.com/onsi/gomega
before_script: go test -i ./...
script: go test ./...
build:
go build jenkins.go
run:
go run jenkins.go
test:
go test -cover
default:
go run jenkins.go
Jenkins
=================
Golang Jenkins hash
[![Build Status](https://travis-ci.org/mtchavez/go-jenkins-hashes.png?branch=master)](https://travis-ci.org/mtchavez/go-jenkins-hashes)
## Install
`go get -u github.com/mtchavez/jenkins`
## Usage
Jenkins follows the [Hash32](http://golang.org/pkg/hash/#Hash32) interface from the Go standard library
```go
// Create a new hash
jenkhash := New()
// Write a string of bytes to hash
key := []byte("my-random-key")
length, err := jenkhash(key)
// Get uint32 sum of hash
sum := jenkhash.Sum32()
// Sum hash with byte string
sumbytes := jenkhash.Sum(key)
```
## Testing
Uses [Ginkgo](http://onsi.github.io/ginkgo/) for testing.
Run via `make test` which will run `go test -cover`
## Documentation
Docs on [godoc](http://godoc.org/github.com/mtchavez/jenkins)
## License
Written by Chavez
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
package jenkins
import "hash"
type jenkhash uint32
func New() hash.Hash32 {
var j jenkhash = 0
return &j
}
func (j *jenkhash) Write(key []byte) (int, error) {
hash := *j
for _, b := range key {
hash += jenkhash(b)
hash += (hash << 10)
hash ^= (hash >> 6)
}
hash += (hash << 3)
hash ^= (hash >> 11)
hash += (hash << 15)
*j = hash
return len(key), nil
}
func (j *jenkhash) Reset() {
*j = 0
}
func (j *jenkhash) Size() int {
return 4
}
func (j *jenkhash) BlockSize() int {
return 1
}
func (j *jenkhash) Sum32() uint32 {
return uint32(*j)
}
func (j *jenkhash) Sum(in []byte) []byte {
v := j.Sum32()
return append(in, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
}
package jenkins
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestJenkins(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Jenkins Suite")
}
package jenkins
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"hash"
)
var _ = Describe("Jenkins", func() {
var jhash hash.Hash32
var key []byte
BeforeEach(func() {
jhash = New()
key = []byte("Apple")
})
Describe("New", func() {
It("returns jenkhash", func() {
var h *jenkhash
Expect(jhash).To(BeAssignableToTypeOf(h))
})
It("initializes offset to 0", func() {
Expect(jhash.Sum32()).To(Equal(uint32(0)))
})
})
Describe("Write", func() {
It("returns key length", func() {
length, _ := jhash.Write(key)
Expect(length).To(Equal(5))
})
It("has no error", func() {
_, err := jhash.Write(key)
Expect(err).To(BeNil())
})
})
Describe("Reset", func() {
It("sets back to 0", func() {
Expect(jhash.Sum32()).To(Equal(uint32(0)))
jhash.Write(key)
Expect(jhash.Sum32()).NotTo(Equal(uint32(0)))
jhash.Reset()
Expect(jhash.Sum32()).To(Equal(uint32(0)))
})
})
Describe("Size", func() {
It("is 4", func() {
Expect(jhash.Size()).To(Equal(4))
})
})
Describe("BlockSize", func() {
It("is 1", func() {
Expect(jhash.BlockSize()).To(Equal(1))
})
})
Describe("Sum32", func() {
It("defaults to 0", func() {
Expect(jhash.Sum32()).To(Equal(uint32(0)))
})
It("sums hash", func() {
jhash.Write(key)
Expect(jhash.Sum32()).To(Equal(uint32(884782484)))
})
})
Describe("Sum", func() {
It("default 0 hash byte returned", func() {
expected := []byte{0x41, 0x70, 0x70, 0x6c, 0x65, 0x0, 0x0, 0x0, 0x0}
Expect(jhash.Sum(key)).To(Equal(expected))
})
It("returns sum byte array", func() {
jhash.Write(key)
expected := []byte{0x41, 0x70, 0x70, 0x6c, 0x65, 0x34, 0xbc, 0xb5, 0x94}
Expect(jhash.Sum(key)).To(Equal(expected))
})
})
})
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论