// // /nodes/ => POST => register new node // func ExampleFactories_Register() { fa := models.Factory{ Name: "factory_1", Host: "localhost:9001", } body, _ := marshaller.IoReader(fa) req, err := http.NewRequest("POST", "http://example.com/nodes", body) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() db, _ := redis.NewDB(config) storage := storage.New(db) if err != nil { fmt.Printf("%s\n", err) return } dataset := storage.NewDataset("puaro") storage.Insert(dataset) newCluster := cluster.NewCluster("test", db) factory := api.FactoryHandler{newCluster} factory.Register(w, req, nil) fmt.Printf("%d", w.Code) newCluster.Factories.Clean() // Output: // 200 }
func ExampleFactories_Index() { factory1 := &models.Factory{Name: "factory_1"} factory2 := &models.Factory{Name: "factory_2"} factory3 := &models.Factory{Name: "factory_3"} body, _ := marshaller.IoReader(factory1) req, err := http.NewRequest("POST", "http://example.com/factories", body) if err != nil { log.Fatal(err) } w := httptest.NewRecorder() db, _ := redis.NewDB(config) storage := storage.New(db) dataset := storage.NewDataset("puaro") storage.Insert(dataset) newCluster := cluster.NewCluster("test", db) newCluster.Register(factory1) newCluster.Register(factory2) newCluster.Register(factory3) factory := api.FactoryHandler{newCluster} factory.Index(w, req, nil) factoriesResponse := []string{} json.Unmarshal([]byte(w.Body.String()), &factoriesResponse) fmt.Printf("%d - %d", w.Code, len(factoriesResponse)) // Output: // 200 - 3 }