Skip to content

Commit

Permalink
feat(!!): update lib and code to make the tests pass again
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Feb 24, 2021
1 parent 219bd02 commit de07f04
Show file tree
Hide file tree
Showing 50 changed files with 648 additions and 480 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ explorer/node_modules
explorer/dist
dist/*
app/assets/bindata.go
data
data/*
admin/build
admin/node_modules
vendor
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ matrix:
# env: TEST_FRONTEND=on TRAVIS_NODE_VERSION="0.12"

before_script:
- curl https://dl.influxdata.com/influxdb/releases/influxdb-0.13.0_linux_amd64.tar.gz | tar xvzf -
- ./influxdb-0.13.0-1/usr/bin/influxd &
- sleep 2
- if [ "$TEST_BACKEND" = "on" ]; then
psql -c 'create database travis_ci_test;' -U postgres;
cp -f test/config_travis.toml test/config_test.toml;
Expand Down
46 changes: 19 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,34 @@ PID = .pid
GO_FILES = $(shell find . -type f -name "*.go")
GONODE_MODULES = $(shell ls -d ./modules/* | grep -v go)
GONODE_CORE = $(shell ls -d ./core/* | grep -v go)
GO_PATH = $(shell go env GOPATH)

help: ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

define back
$(call docker,back,$(1))
endef

define docker
if [ ! -f /.dockerenv ]; then \
docker-compose run $(1) /bin/bash -c "$(2)"; \
else \
/bin/bash -c "$(2)"; \
fi
endef

shell:
docker-compose run back /bin/bash
GOPATH = $(shell go env GOPATH)

install:
$(call back,glide install)
$(call back,go get github.com/wadey/gocovmerge && go get golang.org/x/tools/cmd/cover && go get golang.org/x/tools/cmd/goimports && go get -u github.com/jteeuwen/go-bindata/...)

test:
$(call back,./app/assets/bindata.sh && go test -v $(GONODE_CORE) $(GONODE_MODULES) ./test/modules)
$(call back,go vet $(GONODE_CORE) $(GONODE_MODULES) ./test/modules/)
./app/assets/bindata.sh
echo "mode: atomic" > data/coverage.out
mkdir -p data

format:
$(call back,gofmt -w $(GONODE_CORE) $(GONODE_MODULES) ./test/modules)
$(call back,go fix $(GONODE_CORE) $(GONODE_MODULES) ./test/modules)
$(call back,go vet $(GONODE_CORE) $(GONODE_MODULES) ./test/modules)
GONODE_TEST_OFFLINE=true GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverprofile=data/coverage_core.out $(GONODE_CORE)
GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverprofile=data/coverage_modules.out $(GONODE_MODULES)
GOPATH=${GOPATH} go test -v -failfast -covermode=atomic -coverpkg ./... -coverprofile=data/coverage_integration.out ./test/modules
go vet $(GONODE_CORE) $(GONODE_MODULES) ./test/modules/

tail -n +2 data/coverage_core.out >> data/coverage.out
tail -n +2 data/coverage_modules.out >> data/coverage.out
tail -n +2 data/coverage_integration.out >> data/coverage.out
go tool cover -html data/coverage.out -o data/coverage.html

run:
docker-compose kill
docker-compose up
GOPATH=${GOPATH} `go env GOPATH`/bin/modd

format:
gofmt -w $(GONODE_CORE) $(GONODE_MODULES) ./test/modules
go fix $(GONODE_CORE) $(GONODE_MODULES) ./test/modules
go vet $(GONODE_CORE) $(GONODE_MODULES) ./test/modules

load: ## Load fixtures
curl -XPOST http://localhost:2508/setup/uninstall && exit 0
Expand Down
3 changes: 2 additions & 1 deletion app/assets/bindata.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash

GOPATH=`go env GOPATH`
GO_BINDATA_PATHS="${GOPATH}/src/github.com/rande/gonode/modules/..."
GO_BINDATA_IGNORE="(.*)\.(go|DS_Store)"
GO_BINDATA_OUTPUT="${GOPATH}/src/github.com/rande/gonode/app/assets/bindata.go"
GO_BINDATA_PACKAGE="assets"

echo "Generating bindata file..."
cd ${GOPATH}/src && go-bindata -dev -prefix ${GOPATH}/src -o ${GO_BINDATA_OUTPUT} -pkg ${GO_BINDATA_PACKAGE} -ignore ${GO_BINDATA_IGNORE} ${GO_BINDATA_PATHS}
cd ${GOPATH}/src && ${GOPATH}/bin/go-bindata -dev -prefix ${GOPATH}/src -o ${GO_BINDATA_OUTPUT} -pkg ${GO_BINDATA_PACKAGE} -ignore ${GO_BINDATA_IGNORE} ${GO_BINDATA_PATHS}

echo "Done!"
2 changes: 1 addition & 1 deletion app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package main
import (
"os"

log "github.com/Sirupsen/logrus"
"github.com/mitchellh/cli"
"github.com/rande/goapp"
"github.com/rande/gonode/app/assets"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/rande/gonode/modules/search"
"github.com/rande/gonode/modules/setup"
"github.com/rande/gonode/modules/user"
log "github.com/sirupsen/logrus"
)

func Configure(configFile string) *goapp.Lifecycle {
Expand Down
2 changes: 1 addition & 1 deletion app/server.toml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test= true

[databases.master]
type = "master"
dsn = "postgres://postgres:gonode@database/gonode?sslmode=disable"
dsn = "postgres://postgres:gonode@localhost/gonode?sslmode=disable"
enabled = true
prefix = "prod"

Expand Down
3 changes: 1 addition & 2 deletions core/bindata/bindata_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package bindata

import (
log "github.com/Sirupsen/logrus"
"github.com/flosch/pongo2"
"github.com/rande/goapp"
"github.com/rande/gonode/core/config"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
)

Expand All @@ -27,7 +27,6 @@ func Configure(l *goapp.Lifecycle, conf *config.Config) {
})

l.Prepare(func(app *goapp.App) error {

if !app.Has("goji.mux") {
return nil
}
Expand Down
4 changes: 1 addition & 3 deletions core/bindata/bindata_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"strings"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
)

Expand Down Expand Up @@ -88,7 +88,5 @@ func ConfigureBinDataMux(mux *web.Mux, Asset func(name string) ([]byte, error),

res.WriteHeader(404)
res.Write([]byte("<html><head><title>Page not found</title></head><body><h1>Page not found</h1></body></html>"))

return
})
}
2 changes: 1 addition & 1 deletion core/commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"flag"
"net/http"

log "github.com/Sirupsen/logrus"
"github.com/mitchellh/cli"
"github.com/rande/goapp"
"github.com/rande/gonode/core/config"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/bind"
"github.com/zenazn/goji/graceful"
"github.com/zenazn/goji/web"
Expand Down
4 changes: 2 additions & 2 deletions core/commands/cli_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"net/http"
"time"

log "github.com/Sirupsen/logrus"
sq "github.com/lann/squirrel"
sq "github.com/Masterminds/squirrel"
"github.com/lib/pq"
"github.com/rande/goapp"
"github.com/rande/gonode/core/config"
"github.com/rande/gonode/core/vault"
"github.com/rande/gonode/modules/base"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
)
Expand Down
11 changes: 0 additions & 11 deletions core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ key = "ZeSecretKey0oo"
[logger.fields]
app = "gonode"
[logger.hooks]
[logger.hooks.default]
service = "influxdb"
dsn = "http://localhost:8086"
tags = ["app.core"]
database = "stats"
level = "debug"
`, config)

assert.NoError(t, err)
Expand Down Expand Up @@ -142,9 +134,6 @@ key = "ZeSecretKey0oo"

// test logger
assert.Equal(t, map[string]string{"app": "gonode"}, config.Logger.Fields)
assert.Equal(t, "influxdb", config.Logger.Hooks["default"]["service"])
assert.Equal(t, []interface{}{"app.core"}, config.Logger.Hooks["default"]["tags"])
assert.Equal(t, "debug", config.Logger.Hooks["default"]["level"])

// debug
config.Guard.Jwt.Login.Path = `^\/nodes\/(.*)$`
Expand Down
2 changes: 1 addition & 1 deletion core/guard/guard_jwt_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"regexp"
"time"

log "github.com/Sirupsen/logrus"
"github.com/dgrijalva/jwt-go"
"github.com/gorilla/schema"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/bcrypt"
)

Expand Down
2 changes: 1 addition & 1 deletion core/guard/guard_jwt_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"net/http"
"regexp"

log "github.com/Sirupsen/logrus"
"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request"
log "github.com/sirupsen/logrus"
)

// this authenticator will create a JWT Token from a standard form
Expand Down
2 changes: 1 addition & 1 deletion core/guard/guard_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"net/http"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
)

Expand Down
18 changes: 1 addition & 17 deletions core/logger/logger_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/Abramovic/logrus_influxdb"
log "github.com/Sirupsen/logrus"
influxdb "github.com/influxdata/influxdb/client/v2"
"github.com/rande/goapp"
"github.com/rande/gonode/core/config"
"github.com/rande/gonode/core/helper"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
)

Expand Down Expand Up @@ -60,19 +57,6 @@ func GetHook(conf map[string]interface{}) (log.Hook, error) {
}

switch conf["service"] {
case "influxdb":
c, _ := influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: GetValue("url", conf, "http://localhost:8086").(string),
Timeout: 5 * time.Second,
Username: GetValue("username", conf, "").(string),
Password: GetValue("password", conf, "").(string),
UserAgent: "GoNode InfluxDBClient",
})

return logrus_influxdb.NewInfluxDB(&logrus_influxdb.Config{
Database: GetValue("database", conf, "gonode").(string),
Tags: tags,
}, c)
}

return nil, NoHookHandlerError
Expand Down
2 changes: 1 addition & 1 deletion core/logger/logger_logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package logger

import (
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

type DispatchHook struct {
Expand Down
2 changes: 1 addition & 1 deletion core/logger/logger_logrus_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package logger

import (
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/mock"
)

Expand Down
42 changes: 1 addition & 41 deletions core/logger/logger_logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
package logger

import (
"fmt"
"os"
"testing"

log "github.com/Sirupsen/logrus"
"github.com/rande/gonode/core/config"
"github.com/stretchr/testify/assert"
log "github.com/sirupsen/logrus"
)

func Test_Dispatch_SameLevel(t *testing.T) {
Expand Down Expand Up @@ -65,39 +61,3 @@ func Test_Dispatch_Fatal(t *testing.T) {

h.AssertCalled(t, "Fire", e)
}

func Test_Config_Influx(t *testing.T) {
hook, err := GetHook(map[string]interface{}{
"service": "influxdb",
"tags": []string{"salut"},
"url": fmt.Sprintf("http://%s:8086", os.Getenv("INFLUXDB_HOST")),
})

assert.NoError(t, err)
assert.NotNil(t, hook)
}

func Test_Config_Influx_From_Config(t *testing.T) {
conf := &config.Config{
Databases: make(map[string]*config.Database),
}

err := config.LoadConfigurationFromString(`
[logger]
[logger.hooks]
[logger.hooks.default]
service = "influxdb"
url = "http://{{ env "INFLUXDB_HOST" }}:8086"
tags = ["app.core"]
database = "gonode_stats"
level = "debug"
`, conf)

assert.NoError(t, err)

hook, err := GetHook(conf.Logger.Hooks["default"])

assert.NoError(t, err)
assert.NotNil(t, hook)
}
2 changes: 1 addition & 1 deletion core/logger/logger_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"time"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
"github.com/zenazn/goji/web/mutil"
Expand Down
2 changes: 1 addition & 1 deletion core/security/security_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"regexp"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/zenazn/goji/web"
)

Expand Down
2 changes: 1 addition & 1 deletion core/security/security_decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Test_AffirmativeDecision_Abstain_ForceTrue(t *testing.T) {
v.On("Support", s).Return(true)

d := &AffirmativeDecision{
Voters: []Voter{v},
Voters: []Voter{v},
AllowIfAllAbstainDecisions: true, // force
}

Expand Down
3 changes: 1 addition & 2 deletions core/squirrel/squirrel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package squirrel
import (
"testing"

sq "github.com/lann/squirrel"
sq "github.com/Masterminds/squirrel"
"github.com/stretchr/testify/assert"
// "github.com/twinj/uuid"
)

func Test_ExprSlice_With_int(t *testing.T) {
Expand Down
Loading

0 comments on commit de07f04

Please sign in to comment.