Skip to content

Commit

Permalink
Fixing directory size test, testdata dir is being ignored in travis
Browse files Browse the repository at this point in the history
  • Loading branch information
devdinu committed Feb 18, 2020
1 parent 1e2ddb6 commit 62f8b3c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
include:
- stage: test
name: "Unit tests"
script: make test
script: pwd && ls ./agent/testdata/ && ls ./agent && make test
- script: make testcodecov
name: "Unit tests code coverage"
- script: make check-quality
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
all: clean check-quality build testv golangci

APP=kafkq
ALL_PACKAGES=$(shell go list ./...)
SOURCE_DIRS=$(shell go list ./... | cut -d "/" -f4 | uniq)

Expand Down
4 changes: 4 additions & 0 deletions agent/data_navigator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func NewNavigator(datadir string) (Navigator, error) {
}
_, base := filepath.Split(datadir)

_, err = os.Stat(datadir)
if err != nil && os.IsNotExist(err) {
return Navigator{}, err
}
//TODO: validate path existence
return Navigator{
datadir: datadir,
Expand Down
32 changes: 28 additions & 4 deletions agent/data_navigator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"flag"
"path/filepath"
"testing"

Expand All @@ -9,11 +10,19 @@ import (
"github.com/stretchr/testify/require"
)

var integration *bool

func init() {
logger.Setup("none")
logger.Setup("debug")
// Use it for running tests locally as exact directory size differs in linux
integration = flag.Bool("integration", false, "run integration tests")
}

func TestShouldGetTopicInformation(t *testing.T) {
if !*integration {
logger.Infof("Skipping test: %s", t.Name())
t.Skip()
}

dir, err := filepath.Abs("./testdata/datadir")
require.NoError(t, err)
Expand All @@ -34,11 +43,21 @@ func TestShouldGetTopicInformation(t *testing.T) {
}

func TestShouldReturnErrorForInvalidDir(t *testing.T) {
_, err := NewNavigator("somedir")

assert.EqualError(t, err, "stat somedir: no such file or directory")
}

func TestShouldSplitTopicPartition(t *testing.T) {
nav, _ := NewNavigator("somedir")

if !*integration {
logger.Infof("Skipping test: %s", t.Name())
t.Skip()
}
dir, err := filepath.Abs("./testdata/datadir")
require.NoError(t, err)
nav, err := NewNavigator(dir)
require.NoError(t, err)

topic, partition, err := nav.splitTopicPartition("something-topic-1")

Expand All @@ -47,11 +66,16 @@ func TestShouldSplitTopicPartition(t *testing.T) {
assert.Equal(t, 1, partition)
}

func TestBla(t *testing.T) {
func TestDirectorySizeIntegration(t *testing.T) {
flag.Parse()
if !*integration {
logger.Infof("Skipping test: %s", t.Name())
t.Skip()
}
dir, _ := filepath.Abs("./testdata")

di, err := getDirsSize(dir)

require.NoError(t, err)
assert.Equal(t, di, dirInfo{name: dir, sizeBytes: 759})
assert.Equal(t, dirInfo{name: dir, sizeBytes: 759}, di)
}

0 comments on commit 62f8b3c

Please sign in to comment.