Skip to content

Commit

Permalink
Random fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMahe committed Sep 26, 2019
1 parent 31b70c0 commit 4adcc88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ FROM golang:1.13.0-stretch

WORKDIR /project

# install dependencies
COPY go.mod go.sum ./
RUN go mod download

VOLUME /project

# install some dependencies from apt-get.
Expand Down Expand Up @@ -38,6 +34,10 @@ RUN mkdir -p /usr/local/include/gogo/protobuf/ && \
wget -qO- https://github.com/gogo/protobuf/archive/v${gogoprotobuf}.tar.gz | tar -xzf - protobuf-${gogoprotobuf}/gogoproto/gogo.proto && \
mv protobuf-${gogoprotobuf}/gogoproto /usr/local/include/gogo/protobuf/

# install dependencies
COPY go.mod go.sum ./
RUN go mod download

RUN go install github.com/go-bindata/go-bindata/go-bindata
RUN go install github.com/golang/protobuf/protoc-gen-go
RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
Expand Down
7 changes: 6 additions & 1 deletion database/process_db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package database

import (
"errors"
"fmt"

"github.com/gogo/protobuf/proto"
Expand All @@ -10,6 +11,10 @@ import (
"github.com/syndtr/goleveldb/leveldb"
)

var (
errCannotSaveProcessWithoutHash = errors.New("database: can't save process without hash")
)

// ProcessDB describes the API of database package.
type ProcessDB interface {
// Save saves a process to database.
Expand Down Expand Up @@ -108,7 +113,7 @@ func (d *LevelDBProcessDB) Get(hash hash.Hash) (*process.Process, error) {
// If there is an another process that uses the same sid, it'll be deleted.
func (d *LevelDBProcessDB) Save(s *process.Process) error {
if s.Hash.IsZero() {
return errCannotSaveWithoutHash
return errCannotSaveProcessWithoutHash
}

b, err := d.marshal(s)
Expand Down
6 changes: 3 additions & 3 deletions database/service_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
errCannotSaveWithoutHash = errors.New("database: can't save service without hash")
errCannotSaveServiceWithoutHash = errors.New("database: can't save service without hash")
)

// ServiceDB is a database for storing service definition.
Expand All @@ -33,7 +33,7 @@ func NewServiceDB(s store.Store, cdc *codec.Codec) *ServiceDB {
func (d *ServiceDB) unmarshalService(hash hash.Hash, value []byte) (*service.Service, error) {
var s service.Service
if err := d.cdc.UnmarshalBinaryBare(value, &s); err != nil {
return nil, fmt.Errorf("database: could not decode service %q: %s", hash, err)
return nil, fmt.Errorf("database: could not decode service %q: %w", hash.String(), err)
}
return &s, nil
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func (d *ServiceDB) Get(hash hash.Hash) (*service.Service, error) {
// If there is an another service that uses the same sid, it'll be deleted.
func (d *ServiceDB) Save(s *service.Service) error {
if len(s.Hash) == 0 {
return errCannotSaveWithoutHash
return errCannotSaveServiceWithoutHash
}
b, err := d.cdc.MarshalBinaryBare(s)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion database/service_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestServiceDBSave(t *testing.T) {
require.Len(t, ss, 2)

// test service without hash.
require.EqualError(t, db.Save(&service.Service{}), errCannotSaveWithoutHash.Error())
require.EqualError(t, db.Save(&service.Service{}), errCannotSaveServiceWithoutHash.Error())
}

func TestServiceDBGet(t *testing.T) {
Expand Down

0 comments on commit 4adcc88

Please sign in to comment.