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.

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