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.

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