Ejemplo n.º 1
0
func SetupEnv(t *testing.T) TestContext {
	c, clean, err := aetest.NewContext()
	if err != nil {
		t.Fatal(err)
	}

	err = aetools.Load(c, strings.NewReader(SampleEntities), aetools.LoadSync)
	if err != nil {
		defer clean()
		t.Fatal(err)
	}

	s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		b, _ := httputil.DumpRequest(r, true)
		log.Printf("Received request:\n%s\n", string(b))
		enc := json.NewEncoder(w)
		err := enc.Encode(&bigquery.TableDataInsertAllResponse{})
		log.Printf("Error writing response: %v\n", err)
	}))

	// TODO(ronoaldo): enable parallel testing.
	bigquerysync.InsertAllURL = fmt.Sprintf("%s/%%s/%%s/%%s", s.URL)
	bigquerysync.NewClient = func(c context.Context) (*http.Client, error) {
		return &http.Client{}, nil
	}

	tc := &testContext{
		Context: c,
		clean:   clean,
		server:  s,
	}
	return tc
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	client, err := newClient()
	if err != nil {
		log.Fatal(err)
	}

	c, err := remote_api.NewRemoteContext(host, client)
	if err != nil {
		log.Fatalf("Error loading RemoteContext: %s", err.Error())
	}

	switch {
	case dump != "":
		log.Printf("Dumping entities of kind %s...\n", dump)
		err = aetools.Dump(c, os.Stdout, &aetools.Options{Kind: dump, PrettyPrint: pretty})
		if err != nil {
			log.Fatal(err)
		}
	case len(load) > 0:
		log.Println("Loading entities ...")
		for _, f := range load {
			fd, err := os.Open(f)
			if err != nil {
				log.Printf("Error opening %s\n", err.Error())
				continue
			}
			err = aetools.Load(c, fd, &aetools.Options{
				BatchSize: batchSize,
			})
			if err != nil {
				log.Printf("Error loading fixture %s: %s\n", f, err.Error())
			}
			fd.Close()
		}
	default:
		err = aetools.Dump(c, os.Stdout, &aetools.Options{Kind: StatKind, PrettyPrint: true})
		if err != nil {
			log.Fatal(err)
		}
	}
}