func makeSearchItems() int { indexer.Initialize(config.Config) /* Gotta populate the search index */ nodes := make([]*node.Node, 4) roles := make([]*role.Role, 4) envs := make([]*environment.ChefEnvironment, 4) clients := make([]*client.Client, 4) dbags := make([]*databag.DataBag, 4) gob.Register(new(node.Node)) gob.Register(new(role.Role)) gob.Register(new(environment.ChefEnvironment)) gob.Register(new(client.Client)) gob.Register(new(databag.DataBag)) for i := 0; i < 4; i++ { nodes[i], _ = node.New(fmt.Sprintf("node%d", i)) nodes[i].Default["baz"] = fmt.Sprintf("borb") nodes[i].Default["blurg"] = fmt.Sprintf("b%d", i) nodes[i].Save() roles[i], _ = role.New(fmt.Sprintf("role%d", i)) roles[i].Save() envs[i], _ = environment.New(fmt.Sprintf("env%d", i)) envs[i].Save() clients[i], _ = client.New(fmt.Sprintf("client%d", i)) clients[i].Save() dbags[i], _ = databag.New(fmt.Sprintf("databag%d", i)) dbags[i].Save() dbi := make(map[string]interface{}) dbi["id"] = fmt.Sprintf("dbi%d", i) dbi["foo"] = fmt.Sprintf("dbag_item_%d", i) dbags[i].NewDBItem(dbi) } node1 = nodes[0] node2 = nodes[1] node3 = nodes[2] node4 = nodes[3] role1 = roles[0] role2 = roles[1] role3 = roles[2] role4 = roles[3] env1 = envs[0] env2 = envs[1] env3 = envs[2] env4 = envs[3] client1 = clients[0] client2 = clients[1] client3 = clients[2] client4 = clients[3] dbag1 = dbags[0] dbag2 = dbags[1] dbag3 = dbags[2] dbag4 = dbags[3] /* Make this function return something so the compiler's happy building * the tests. */ return 1 }
func TestReportListing(t *testing.T) { uuid := "12b8be8d-a2ef-4fc6-88b3-4c18103b88d%d" gob.Register(new(Report)) for i := 0; i < 3; i++ { u := fmt.Sprintf(uuid, i) r, _ := New(u, "node") r.StartTime = time.Now() r.Save() } rs := GetList() if len(rs) != 3 { t.Errorf("expected 3 items in list, got %d", len(rs)) } n, _ := node.New("node2") for i := 4; i < 6; i++ { u := fmt.Sprintf(uuid, i) r, _ := New(u, n.Name) r.StartTime = time.Now() r.Save() } from := time.Now().Add(-(time.Duration(24*90) * time.Hour)) until := time.Now() ns, nerr := GetNodeList(n.Name, from, until, 100, "") if nerr != nil { t.Errorf(nerr.Error()) } if len(ns) != 2 { t.Errorf("expected 2 items from node 'node2', got %d", len(ns)) } zs, rerr := GetReportList(from, until, 100, "started") if rerr != nil { t.Errorf(rerr.Error()) } rs = GetList() if len(zs) != len(rs) { t.Errorf("Searching on 'started' status here should have returned everything but it didn't") } zs, rerr = GetReportList(from, until, 100, "success") if rerr != nil { t.Errorf(rerr.Error()) } if len(zs) != 0 { t.Errorf("Searching for successful runs should have returned zero results, but returned %d instead", len(zs)) } }
func TestShoveyCreation(t *testing.T) { indexer.Initialize(config.Config) nn := new(node.Node) ns := new(node.NodeStatus) gob.Register(nn) gob.Register(ns) nodes := make([]*node.Node, 5) nodeNames := make([]string, 5) for i := 0; i < 5; i++ { n, _ := node.New(fmt.Sprintf("node-shove-%d", i)) n.Save() err := n.UpdateStatus("up") if err != nil { t.Errorf(err.Error()) } n.Save() nodes[i] = n nodeNames[i] = n.Name } z := new(Shovey) zz := new(ShoveyRun) gob.Register(z) gob.Register(zz) s, err := New("/bin/ls", 300, "100%", nodeNames) if err != nil { t.Errorf(err.Error()) } s2, err := Get(s.RunID) if err != nil { t.Errorf(err.Error()) } if s.RunID != s2.RunID { t.Errorf("Run IDs should have been equal, but weren't. Got %s and %s", s.RunID, s2.RunID) } //err = s.Cancel() //if err != nil { // t.Errorf(err.Error()) //} }
func makeSearchItems() int { indexer.Initialize(config.Config) /* Gotta populate the search index */ nodes := make([]*node.Node, 4) roles := make([]*role.Role, 4) envs := make([]*environment.ChefEnvironment, 4) clients := make([]*client.Client, 4) dbags := make([]*databag.DataBag, 4) gob.Register(new(node.Node)) gob.Register(new(role.Role)) gob.Register(new(environment.ChefEnvironment)) gob.Register(new(client.Client)) gob.Register(new(databag.DataBag)) // circleci is sometimes weird about the index having everything. This // *never* comes up locally. ??? Could possibly be because the indexer // hasn't had a chance to finish indexing? reindexObjs := make([]indexer.Indexable, 0, 4*5) for i := 0; i < 4; i++ { nodes[i], _ = node.New(fmt.Sprintf("node%d", i)) nodes[i].Default["baz"] = fmt.Sprintf("borb") nodes[i].Default["blurg"] = fmt.Sprintf("b%d", i) nodes[i].Save() roles[i], _ = role.New(fmt.Sprintf("role%d", i)) roles[i].Save() envs[i], _ = environment.New(fmt.Sprintf("env%d", i)) envs[i].Save() clients[i], _ = client.New(fmt.Sprintf("client%d", i)) clients[i].Save() dbags[i], _ = databag.New(fmt.Sprintf("databag%d", i)) dbags[i].Save() dbi := make(map[string]interface{}) dbi["id"] = fmt.Sprintf("dbi%d", i) dbi["foo"] = fmt.Sprintf("dbag_item_%d", i) dbags[i].NewDBItem(dbi) reindexObjs = append(reindexObjs, nodes[i]) reindexObjs = append(reindexObjs, roles[i]) reindexObjs = append(reindexObjs, envs[i]) reindexObjs = append(reindexObjs, clients[i]) dbis, _ := dbags[i].AllDBItems() for _, d := range dbis { reindexObjs = append(reindexObjs, d) } } node1 = nodes[0] node2 = nodes[1] node3 = nodes[2] node4 = nodes[3] role1 = roles[0] role2 = roles[1] role3 = roles[2] role4 = roles[3] env1 = envs[0] env2 = envs[1] env3 = envs[2] env4 = envs[3] client1 = clients[0] client2 = clients[1] client3 = clients[2] client4 = clients[3] dbag1 = dbags[0] dbag2 = dbags[1] dbag3 = dbags[2] dbag4 = dbags[3] indexer.ClearIndex() indexer.ReIndex(reindexObjs) /* Make this function return something so the compiler's happy building * the tests. */ return 1 }