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.

50 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. "requests_per_minute": 20,
  14. "storage_provider": {
  15. "type": 0,
  16. "base_path": "assets"
  17. }
  18. }`
  19. t.Run("Settings parsing is successful", func(t *testing.T) {
  20. settings := parseSettings([]byte(file))
  21. assert.Equal(t, "0.0.0.0:8000", settings.Endpoint)
  22. assert.Equal(t, "foobar", settings.Token)
  23. assert.Equal(t, "assets", settings.StorageProvider.BasePath)
  24. })
  25. }
  26. func TestSettingsLoading(t *testing.T) {
  27. t.Run("Settings loading creates default settings.json when none is present", func(t *testing.T) {
  28. fileSystem := afero.NewMemMapFs()
  29. workingDirectory, _ := os.Getwd()
  30. path := filepath.Join(workingDirectory, "settings.json")
  31. // Settings file does not exist in the beginning
  32. doesFileExist, _ := afero.Exists(fileSystem, path)
  33. assert.False(t, doesFileExist)
  34. _, err := LoadSettings(fileSystem)
  35. assert.Nil(t, err)
  36. // Settings file should be present after calling LoadSettings
  37. doesFileExist, _ = afero.Exists(fileSystem, path)
  38. assert.True(t, doesFileExist)
  39. })
  40. }