You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
package settings
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSettingsParsing(t *testing.T) {
|
|
const file string = `{
|
|
"endpoint": "0.0.0.0:8000",
|
|
"token": "foobar",
|
|
"storageProvider": {
|
|
"type": 0,
|
|
"basePath": "assets"
|
|
}
|
|
}`
|
|
|
|
t.Run("Settings parsing is successful", func(t *testing.T) {
|
|
settings := parseSettings([]byte(file))
|
|
|
|
assert.Equal(t, "0.0.0.0:8000", settings.Endpoint)
|
|
assert.Equal(t, "foobar", settings.Token)
|
|
assert.Equal(t, "assets", settings.StorageProvider.BasePath)
|
|
})
|
|
}
|
|
|
|
func TestSettingsLoading(t *testing.T) {
|
|
t.Run("Settings loading creates default settings.json when none is present", func(t *testing.T) {
|
|
fileSystem := afero.NewMemMapFs()
|
|
workingDirectory, _ := os.Getwd()
|
|
|
|
path := filepath.Join(workingDirectory, "settings.json")
|
|
|
|
// Settings file does not exist in the beginning
|
|
doesFileExist, _ := afero.Exists(fileSystem, path)
|
|
assert.False(t, doesFileExist)
|
|
|
|
LoadSettings(fileSystem)
|
|
|
|
// Settings file should be present after calling LoadSettings
|
|
doesFileExist, _ = afero.Exists(fileSystem, path)
|
|
assert.True(t, doesFileExist)
|
|
})
|
|
}
|