func TestInferTableSchema(t *testing.T) { c, clean, err := aetest.NewContext() if err != nil { t.Fatal(err) } defer clean() err = aetools.LoadJSON(c, datastoreStats, aetools.LoadSync) s, err := bigquerysync.SchemaForKind(c, "Account") if err != nil { t.Fatal(err) } j, _ := json.Marshal(s) t.Logf("Decoded schema: '%s'", string(j)) if len(s.Fields) != 4 { t.Errorf("Unexpected field len: %d, expected 4", len(s.Fields)) } for i, f := range s.Fields { if f.Name == "" { t.Errorf("Name of field %d is empty", i) } if f.Type == "" { t.Errorf("Type of field %d is empty", i) } } }
// SchemaHandler prints the JSON schema for a kind using the method // bigquerysync.SchemaForKind. func SchemaHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) t := page{resp: w, req: r} err := r.ParseForm() if err != nil { errorf(c, w, 400, "Invalid request: %v", err) return } schema, err := bigquerysync.SchemaForKind(c, r.Form.Get("kind")) if err != nil { t.ServerError(err) return } e := json.NewEncoder(w) err = e.Encode(schema) if err != nil { t.ServerError(err) } }