Get persistence file path from $STATE_DIRECTORY
This commit is contained in:
parent
765a41f8a1
commit
b19ae59a9c
11
main.go
11
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -114,6 +115,14 @@ func makeSatel(satelAddr string) *satel.Satel {
|
||||||
return satel.NewConfig(satelConn, satel.Config{EventsQueueSize: 10})
|
return satel.NewConfig(satelConn, satel.Config{EventsQueueSize: 10})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPersistenceFilePath() string {
|
||||||
|
var stateDir = os.Getenv("STATE_DIRECTORY")
|
||||||
|
if len(stateDir) != 0 {
|
||||||
|
return filepath.Join(stateDir, PersistenceFilename)
|
||||||
|
}
|
||||||
|
return PersistenceFilename
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
@ -137,7 +146,7 @@ func main() {
|
||||||
|
|
||||||
tpl := template.Must(template.New("TelegramMessage").Parse(TelegramMessageTemplate))
|
tpl := template.Must(template.New("TelegramMessage").Parse(TelegramMessageTemplate))
|
||||||
|
|
||||||
dataStore := MakeDataStore(log.New(os.Stderr, "DataStore", log.Lmicroseconds), PersistenceFilename)
|
dataStore := MakeDataStore(log.New(os.Stderr, "DataStore", log.Lmicroseconds), getPersistenceFilePath())
|
||||||
|
|
||||||
Consume(
|
Consume(
|
||||||
SendToTg(
|
SendToTg(
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetPersistenceFilename(t *testing.T) {
|
||||||
|
var oldStateDir = os.Getenv("STATE_DIRECTORY")
|
||||||
|
os.Setenv("STATE_DIRECTORY", "test_dir")
|
||||||
|
assert.Equal(t, filepath.Join("test_dir", PersistenceFilename), getPersistenceFilePath())
|
||||||
|
os.Setenv("STATE_DIRECTORY", "")
|
||||||
|
assert.Equal(t, PersistenceFilename, getPersistenceFilePath())
|
||||||
|
os.Setenv("STATE_DIRECTORY", oldStateDir)
|
||||||
|
}
|
Loading…
Reference in New Issue