Micro-service for file storage and processing written in Go
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

  1. package settings
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. "github.com/spf13/afero"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestSettingsParsing(t *testing.T) {
  10. const file string = `{
  11. "endpoint": "0.0.0.0:8000",
  12. "token": "foobar",
  13. "storage_provider": {
  14. "type": 0,
  15. "base_path": "assets"
  16. }
  17. }`
  18. t.Run("Settings parsing is successful", func(t *testing.T) {
  19. settings := parseSettings([]byte(file))
  20. assert.Equal(t, "0.0.0.0:8000", settings.Endpoint)
  21. assert.Equal(t, "foobar", settings.Token)
  22. assert.Equal(t, "assets", settings.StorageProvider.BasePath)
  23. })
  24. }
  25. func TestSettingsLoading(t *testing.T) {
  26. t.Run("Settings loading creates default settings.json when none is present", func(t *testing.T) {
  27. fileSystem := afero.NewMemMapFs()
  28. workingDirectory, _ := os.Getwd()
  29. path := filepath.Join(workingDirectory, "settings.json")
  30. // Settings file does not exist in the beginning
  31. doesFileExist, _ := afero.Exists(fileSystem, path)
  32. assert.False(t, doesFileExist)
  33. LoadSettings(fileSystem)
  34. // Settings file should be present after calling LoadSettings
  35. doesFileExist, _ = afero.Exists(fileSystem, path)
  36. assert.True(t, doesFileExist)
  37. })
  38. }