Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
2 changed files with
54 additions and
0 deletions
-
settings/settings.go
-
settings/settings_test.go
|
|
@ -0,0 +1,28 @@ |
|
|
|
package settings |
|
|
|
|
|
|
|
import "encoding/json" |
|
|
|
|
|
|
|
const ( |
|
|
|
Local FileSystemType = iota |
|
|
|
) |
|
|
|
|
|
|
|
type FileSystemType int |
|
|
|
|
|
|
|
type Settings struct { |
|
|
|
Endpoint string |
|
|
|
Token string |
|
|
|
FileSystem FileSystemSettings |
|
|
|
} |
|
|
|
|
|
|
|
type FileSystemSettings struct { |
|
|
|
Type FileSystemType |
|
|
|
BasePath string |
|
|
|
} |
|
|
|
|
|
|
|
func ParseSettings(data []byte) Settings { |
|
|
|
settings := Settings{} |
|
|
|
|
|
|
|
json.Unmarshal(data, &settings) |
|
|
|
|
|
|
|
return settings |
|
|
|
} |
|
|
@ -0,0 +1,26 @@ |
|
|
|
package settings |
|
|
|
|
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
|
|
|
|
|
func TestSettingsLoading(t *testing.T) { |
|
|
|
const file string = `{ |
|
|
|
"endpoint": "0.0.0.0:8000", |
|
|
|
"token": "foobar", |
|
|
|
"fileSystem": { |
|
|
|
"type": 0, |
|
|
|
"basePath": "assets" |
|
|
|
} |
|
|
|
}` |
|
|
|
|
|
|
|
t.Run("Settings parsing is successful", func(t *testing.T) { |
|
|
|
settings := ParseSettings([]byte(file)) |
|
|
|
|
|
|
|
assert.Equal(t, "0.0.0.0:8000", settings.Endpoint) |
|
|
|
assert.Equal(t, "foobar", settings.Token) |
|
|
|
assert.Equal(t, "assets", settings.FileSystem.BasePath) |
|
|
|
}) |
|
|
|
} |