storj/pkg/provider/cert_authority_test.go
Bryan White 2a0c4e60d2
preparing for use of customtype gogo extension with NodeID type (#693)
* preparing for use of `customtype` gogo extension with `NodeID` type

* review changes

* preparing for use of `customtype` gogo extension with `NodeID` type

* review changes

* wip

* tests passing

* wip fixing tests

* more wip test fixing

* remove NodeIDList from proto files

* linter fixes

* linter fixes

* linter/review fixes

* more freaking linter fixes

* omg just kill me - linterrrrrrrr

* travis linter, i will muder you and your family in your sleep

* goimports everything - burn in hell travis

* goimports update

* go mod tidy
2018-11-29 19:39:27 +01:00

81 lines
1.8 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package provider
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// newTestCA returns a ca with a default difficulty and concurrency for use in tests
func newTestCA(ctx context.Context) (*FullCertificateAuthority, error) {
return NewCA(ctx, NewCAOptions{
Difficulty: 12,
Concurrency: 4,
})
}
func TestNewCA(t *testing.T) {
expectedDifficulty := uint16(4)
ca, err := NewCA(context.Background(), NewCAOptions{
Difficulty: expectedDifficulty,
Concurrency: 5,
})
assert.NoError(t, err)
assert.NotEmpty(t, ca)
actualDifficulty, err := ca.ID.Difficulty()
assert.NoError(t, err)
assert.True(t, actualDifficulty >= expectedDifficulty)
}
func TestFullCertificateAuthority_NewIdentity(t *testing.T) {
check := func(err error, v interface{}) {
if !assert.NoError(t, err) || !assert.NotEmpty(t, v) {
t.Fail()
}
}
ca, err := newTestCA(context.Background())
check(err, ca)
fi, err := ca.NewIdentity()
check(err, fi)
assert.Equal(t, ca.Cert, fi.CA)
assert.Equal(t, ca.ID, fi.ID)
assert.NotEqual(t, ca.Key, fi.Key)
assert.NotEqual(t, ca.Cert, fi.Leaf)
err = fi.Leaf.CheckSignatureFrom(ca.Cert)
assert.NoError(t, err)
}
func NewCABenchmark(b *testing.B, difficulty uint16, concurrency uint) {
for i := 0; i < b.N; i++ {
_, _ = NewCA(context.Background(), NewCAOptions{
Difficulty: difficulty,
Concurrency: concurrency,
})
}
}
func BenchmarkNewCA_Difficulty8_Concurrency1(b *testing.B) {
NewCABenchmark(b, 8, 1)
}
func BenchmarkNewCA_Difficulty8_Concurrency2(b *testing.B) {
NewCABenchmark(b, 8, 2)
}
func BenchmarkNewCA_Difficulty8_Concurrency5(b *testing.B) {
NewCABenchmark(b, 8, 5)
}
func BenchmarkNewCA_Difficulty8_Concurrency10(b *testing.B) {
NewCABenchmark(b, 8, 10)
}