// Test for indendet JsonLangWriter func TestWriteFileIndent(t *testing.T) { str := make(map[string]interface{}) str["a"] = "b" expected := "{\n \"a\": \"b\"\n}" w := NewJsonIndentLangWriter() target := bytes.NewBufferString("") w.WriteTo(str, target) json := target.String() assert.Equals(t, expected, strings.TrimSpace(json)) }
func TestOpenURL(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "some csv") })) defer ts.Close() f, err := LoadUri(ts.URL) assert.Nil(t, err, "error") b, _ := ioutil.ReadAll(f) assert.Equals(t, "some csv", string(b)) }
// Test for JsonLangWriter func TestWriteFile(t *testing.T) { str := make(map[string]interface{}) str["test"] = make(map[string]string) str["test"].(map[string]string)["key"] = "value" str["another"] = make(map[string]interface{}) str["another"].(map[string]interface{})["test"] = make(map[string]int) str["another"].(map[string]interface{})["test"].(map[string]int)["key"] = 42 w := NewJsonLangWriter() target := bytes.NewBufferString("") w.WriteTo(str, target) json := target.String() expected := "{\"another\":{\"test\":{\"key\":42}},\"test\":{\"key\":\"value\"}}" assert.Equals(t, expected, strings.TrimSpace(json)) }