func ExampleDataset_Index() { d1 := &storage.Dataset{Name: "Iris"} d2 := &storage.Dataset{Name: "Iris"} db, _ := redis.NewDB(config) storage := storage.New(db) storage.Clean() storage.Insert(d1) storage.Insert(d2) req, _ := http.NewRequest("GET", "/datasets/", nil) dataset := &api.DatasetHandler{storage} resp := httptest.NewRecorder() dataset.Index(resp, req, nil) datasets := []string{} unmarshaller.IoReader(resp.Body, &datasets) fmt.Printf("%d\n", resp.Code) fmt.Printf("Size %d", len(datasets)) // Output: // 200 // Size 2 }
func TestStorage_Datasets(t *testing.T) { bucket, _ := redis.NewBucket(config) dataset1 := storage.NewDataset("posts", bucket) dataset2 := storage.NewDataset("users", bucket) storage := storage.New(bucket) storage.Clean() storage.Insert(dataset1) storage.Insert(dataset2) datasets := storage.Datasets() if len(datasets) != 2 { t.Errorf("Want 2 got %d\n", len(datasets)) } }
func ExampleInstance_Create() { config, _ := puaro.ConfigFromFile("../../configs/test.json") ds := &storage.Dataset{Name: "Iris"} attrs := &instance.Attributes{ "attr1": "value1", "attr2": "value2", "attr3": "value3", } ps := httprouter.Params{ httprouter.Param{"dataset", "iris"}, httprouter.Param{"collection", "satosa"}, } params, _ := marshaller.IoReader(attrs) req, _ := http.NewRequest("POST", "/", params) db, _ := redis.NewDB(config) storage := storage.New(db) storage.Clean() if err := storage.Insert(ds); err != nil { fmt.Printf("%s\n", err) return } instance := api.InstanceHandler{storage} resp := httptest.NewRecorder() instance.Create(resp, req, ps) fmt.Printf("RESPONSE CODE: %d\n", resp.Code) // Output: // RESPONSE CODE: 200 }