Skip to content

Commit

Permalink
init log_data_path (#85)
Browse files Browse the repository at this point in the history
* init log_data_path
* v0.2.1 for bugfix
  • Loading branch information
jmnote authored May 31, 2023
1 parent 22ff207 commit 01aa33c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := v0.2.0
VERSION := v0.2.1
IMAGE := ghcr.io/kuoss/lethe:$(VERSION)

install-dev:
Expand Down
6 changes: 6 additions & 0 deletions storage/fileservice/fileservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fileservice

import (
"fmt"
"os"

"github.com/kuoss/lethe/config"
storagedriver "github.com/kuoss/lethe/storage/driver"
Expand All @@ -18,6 +19,11 @@ func New(cfg *config.Config) (*FileService, error) {
if err != nil {
return nil, fmt.Errorf("factory.Get err: %w", err)
}
// TODO: use driver
err = os.MkdirAll(cfg.LogDataPath(), 0755)
if err != nil {
return nil, fmt.Errorf("mkdirAll err: %w", err)
}
return &FileService{cfg, driver}, nil
}

Expand Down
27 changes: 27 additions & 0 deletions storage/fileservice/fileservice_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package fileservice

import (
"os"
"testing"

"github.com/kuoss/lethe/config"
"github.com/stretchr/testify/assert"
)

Expand All @@ -11,3 +13,28 @@ func TestNew(t *testing.T) {
assert.Equal(t, "filesystem", fileService.driver.Name())
assert.Equal(t, "tmp/init", fileService.driver.RootDirectory())
}

func TestNewTemp(t *testing.T) {
cfg, err := config.New("test")
assert.NoError(t, err)
assert.NotEmpty(t, cfg)

dataPath := "tmp/temp" // caution: RemoveAll()

cfg.SetLogDataPath(dataPath)
tempFileService, err := New(cfg)
assert.NoError(t, err)
assert.NotEmpty(t, tempFileService)
assert.DirExists(t, dataPath) // exists

// duplicate ok
cfg.SetLogDataPath(dataPath)
tempFileService2, err := New(cfg)
assert.NoError(t, err)
assert.NotEmpty(t, tempFileService2)
assert.DirExists(t, dataPath) // exists

// clean up
err = os.RemoveAll(dataPath)
assert.NoError(t, err)
}

0 comments on commit 01aa33c

Please sign in to comment.