Skip to content

Commit

Permalink
validate should return error (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bivas authored Nov 27, 2018
1 parent 939adca commit c791ade
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 33 deletions.
53 changes: 51 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
RPM_PATH = "iguazio_yum"
DEB_PATH = "iguazio_deb"
BINARY_NAME = "igz-fuse"
RELEASE_VERSION = "0.6.0"
RELEASE_VERSION = "0.6.1"
DOCKER_HUB_USER = "iguaziodocker"

.PHONY: build
build:
build: lint vet
docker build --tag $(DOCKER_HUB_USER)/flex-fuse:unstable .

.PHONY: download
Expand All @@ -29,3 +29,52 @@ endif
ifndef RELEASE_VERSION
$(error RELEASE_VERSION must be set)
endif

.PHONY: lint
lint: ensure-gopath
@echo Installing linters...
go get -u gopkg.in/alecthomas/gometalinter.v2
@$(GOPATH)/bin/gometalinter.v2 --install

@echo Linting...
@$(GOPATH)/bin/gometalinter.v2 \
--deadline=300s \
--disable-all \
--enable-gc \
--enable=deadcode \
--enable=goconst \
--enable=gofmt \
--enable=golint \
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=misspell \
--enable=staticcheck \
--enable=unconvert \
--enable=varcheck \
--enable=vet \
--enable=vetshadow \
--enable=errcheck \
--exclude="_test.go" \
--exclude="comment on" \
--exclude="error should be the last" \
--exclude="should have comment" \
./cmd/... ./pkg/...

@echo Done.

.PHONY: vet
vet:
go vet ./cmd/...
go vet ./pkg/...

.PHONY: test
test:
go test -v ./cmd/...
go test -v ./pkg/...

.PHONY: ensure-gopath
check-gopath:
ifndef GOPATH
$(error GOPATH must be set)
endif
2 changes: 1 addition & 1 deletion cmd/fuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func main() {
}

journal.Info("Completed flex flow", "result", result)
result.ToJson()
result.ToJSON()
}
16 changes: 9 additions & 7 deletions pkg/flex/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (m *Mounter) mountAsLink() *Response {
response := &Response{}
if !isMountPoint(targetPath) {
journal.Debug("Creating folder", "target", targetPath)
os.MkdirAll(targetPath, 0755)
if err := os.MkdirAll(targetPath, 0755); err != nil {
return Fail(fmt.Sprintf("unable to create target %s", targetPath), err)
}
response = m.doMount(targetPath)
}

Expand All @@ -87,7 +89,9 @@ func (m *Mounter) mountAsLink() *Response {
return Fail(fmt.Sprintf("unable to remove target %s", m.Target), err)
}

os.Symlink(targetPath, m.Target)
if err := os.Symlink(targetPath, m.Target); err != nil {
return Fail(fmt.Sprintf("unable to create link %s to target %s", targetPath, m.Target), err)
}
return response
}

Expand Down Expand Up @@ -127,7 +131,7 @@ func (m *Mounter) Unmount() *Response {

func (m *Mounter) validate() error {
if m.Spec.Username == "" || m.Spec.AccessKey == "" {
errors.New("missing username or access key")
return errors.New("missing username or access key")
}
return nil
}
Expand Down Expand Up @@ -155,18 +159,16 @@ func Mount(target, options string) *Response {
mounter, err := NewMounter(target, options)
if err != nil {
return Fail("unable to create mounter", err)
} else {
return mounter.Mount()
}
return mounter.Mount()
}

func Unmount(target string) *Response {
mounter, err := NewMounter(target, "")
if err != nil {
return Fail("unable to create mounter", err)
} else {
return mounter.Unmount()
}
return mounter.Unmount()
}

func Init() *Response {
Expand Down
8 changes: 2 additions & 6 deletions pkg/flex/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ func (c *Config) DataURLs(cluster string) (string, error) {
if err != nil {
return "", err
}
result := make([]string, len(clusterConfig.DataUrls), len(clusterConfig.DataUrls))
for index, item := range clusterConfig.DataUrls {
result[index] = item
}
return strings.Join(result, ","), nil
return strings.Join(clusterConfig.DataUrls, ","), nil
}

type Response struct {
Expand All @@ -74,7 +70,7 @@ func (r *Response) String() string {
return fmt.Sprintf("Response[Status=%s, Message=%s]", r.Status, r.Message)
}

func (r *Response) ToJson() {
func (r *Response) ToJSON() {
jsonBytes, err := json.Marshal(r)
if err != nil {
fmt.Printf(`{"status": "Failure", "Message": "%s"}`, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/flex/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func Success(message string) *Response {
}

func Fail(message string, err error) *Response {
journal.Warn("Failed", "message", message, "err", err.Error())

if err != nil {
journal.Warn("Failed", "message", message, "err", err.Error())
return MakeResponse("Failure", fmt.Sprintf("%s. %s", message, err))
}
return MakeResponse("Failure", fmt.Sprintf("%s", message))
journal.Warn("Failed", "message", message)
return MakeResponse("Failure", message)
}
28 changes: 14 additions & 14 deletions pkg/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nuclio/logger"
)

var j = JournalLogger{}
var j = Logger{}

func Error(message interface{}, vars ...interface{}) {
j.Error(message, vars...)
Expand All @@ -24,54 +24,54 @@ func Debug(message interface{}, vars ...interface{}) {
j.Debug(message, vars...)
}

type JournalLogger struct {
type Logger struct {
}

func (j *JournalLogger) journal(priority journal.Priority, message interface{}, vars ...interface{}) {
func (j *Logger) journal(priority journal.Priority, message interface{}, vars ...interface{}) {
format := ""
if len(vars) > 0 {
format = fmt.Sprintf("%s: %s", message, vars)
} else {
format = fmt.Sprint(message)
}
journal.Send(format, priority, nil)
journal.Send(format, priority, nil) // nolint: errcheck
}

func (j *JournalLogger) Error(message interface{}, vars ...interface{}) {
func (j *Logger) Error(message interface{}, vars ...interface{}) {
j.journal(journal.PriErr, message, vars...)
}

func (j *JournalLogger) Warn(message interface{}, vars ...interface{}) {
func (j *Logger) Warn(message interface{}, vars ...interface{}) {
j.journal(journal.PriWarning, message, vars...)
}

func (j *JournalLogger) Info(message interface{}, vars ...interface{}) {
func (j *Logger) Info(message interface{}, vars ...interface{}) {
j.journal(journal.PriInfo, message, vars...)
}

func (j *JournalLogger) Debug(message interface{}, vars ...interface{}) {
func (j *Logger) Debug(message interface{}, vars ...interface{}) {
j.journal(journal.PriDebug, message, vars...)
}

func (j *JournalLogger) ErrorWith(message interface{}, vars ...interface{}) {
func (j *Logger) ErrorWith(message interface{}, vars ...interface{}) {
j.journal(journal.PriErr, message, vars...)
}

func (j *JournalLogger) WarnWith(message interface{}, vars ...interface{}) {
func (j *Logger) WarnWith(message interface{}, vars ...interface{}) {
j.journal(journal.PriWarning, message, vars...)
}

func (j *JournalLogger) InfoWith(message interface{}, vars ...interface{}) {
func (j *Logger) InfoWith(message interface{}, vars ...interface{}) {
j.journal(journal.PriInfo, message, vars...)
}

func (j *JournalLogger) DebugWith(message interface{}, vars ...interface{}) {
func (j *Logger) DebugWith(message interface{}, vars ...interface{}) {
j.journal(journal.PriDebug, message, vars...)
}

func (j *JournalLogger) Flush() {
func (j *Logger) Flush() {
}

func (j *JournalLogger) GetChild(name string) logger.Logger {
func (j *Logger) GetChild(name string) logger.Logger {
return j
}

0 comments on commit c791ade

Please sign in to comment.