diff --git a/mock/mock.go b/mock/mock.go index 8267e0f..f284929 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -25,6 +25,21 @@ func ParseJsonFromFilePath(file string, intoStruct interface{}) error { return nil } +func JsonFromFilePathToString(file string) (string, error) { + jsonFile, err := os.Open(file) + if err != nil { + return "", err + } + defer jsonFile.Close() + + byteValue, err := ioutil.ReadAll(jsonFile) + if err != nil { + return "", err + } + + return string(byteValue), nil +} + func CreateMockedAPI(funcsMap map[string]func(http.ResponseWriter, *http.Request)) http.Handler { r := http.NewServeMux() for pattern, f := range funcsMap { diff --git a/mock/mock_test.go b/mock/mock_test.go index 8408d60..c94568f 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -41,3 +41,11 @@ func TestParseJsonFromFilePath(t *testing.T) { assert.Nil(t, err) assert.True(t, s.Status) } + +func TestJsonFromFilePathToString(t *testing.T) { + data, err := JsonFromFilePathToString("test.json") + assert.Nil(t, err) + assert.Equal(t, `{ + "status": true +}`, data) +}