|
@ -1,12 +1,15 @@ |
|
|
package settings |
|
|
package settings |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"os" |
|
|
|
|
|
"path/filepath" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/afero" |
|
|
"github.com/stretchr/testify/assert" |
|
|
"github.com/stretchr/testify/assert" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func TestSettingsLoading(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestSettingsParsing(t *testing.T) { |
|
|
const file string = `{ |
|
|
const file string = `{ |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"token": "foobar", |
|
|
"token": "foobar", |
|
@ -24,3 +27,22 @@ func TestSettingsLoading(t *testing.T) { |
|
|
assert.Equal(t, "assets", settings.StorageProvider.BasePath) |
|
|
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) |
|
|
|
|
|
}) |
|
|
|
|
|
} |