Nest packages under pkg

This commit is contained in:
Eric Meyer
2017-11-06 13:06:03 -06:00
parent cf5f2f28db
commit f4a603efcb
36 changed files with 45 additions and 54 deletions
+18
View File
@@ -0,0 +1,18 @@
package observers
import (
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/8thlight/vulcanizedb/pkg/repositories"
)
type BlockchainDbObserver struct {
repository repositories.Repository
}
func NewBlockchainDbObserver(repository repositories.Repository) BlockchainDbObserver {
return BlockchainDbObserver{repository: repository}
}
func (observer BlockchainDbObserver) NotifyBlockAdded(block core.Block) {
observer.repository.CreateBlock(block)
}
@@ -0,0 +1,38 @@
package observers_test
import (
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/8thlight/vulcanizedb/pkg/observers"
"github.com/8thlight/vulcanizedb/pkg/repositories"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Saving blocks to the database", func() {
var repository *repositories.InMemory
BeforeEach(func() {
repository = repositories.NewInMemory()
})
It("implements the observer interface", func() {
var observer core.BlockchainObserver = observers.NewBlockchainDbObserver(repository)
Expect(observer).NotTo(BeNil())
})
It("saves a block with one transaction", func() {
block := core.Block{
Number: 123,
Transactions: []core.Transaction{{}},
}
observer := observers.NewBlockchainDbObserver(repository)
observer.NotifyBlockAdded(block)
savedBlock := repository.FindBlockByNumber(123)
Expect(savedBlock).NotTo(BeNil())
Expect(len(savedBlock.Transactions)).To(Equal(1))
})
})
@@ -0,0 +1,18 @@
package observers
import (
"fmt"
"time"
"github.com/8thlight/vulcanizedb/pkg/core"
)
type BlockchainLoggingObserver struct{}
func (blockchainObserver BlockchainLoggingObserver) NotifyBlockAdded(block core.Block) {
fmt.Printf("New block was added: %d\n"+
"\tTime: %v\n"+
"\tGas Limit: %d\n"+
"\tGas Used: %d\n"+
"\tNumber of Transactions %d\n", block.Number, time.Unix(block.Time, 0), block.GasLimit, block.GasUsed, len(block.Transactions))
}
+13
View File
@@ -0,0 +1,13 @@
package observers_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestObservers(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Observers Suite")
}