func TestChooseRandomFriends(t *testing.T) { cfg.SetNode(node.CreateMockNode()) mockPeers := createMockPeers(100) nFriends := 10 test, err := chooseRandomFriends(mockPeers, nFriends) assert.NoError(t, err, "(nFrineds > 0) Choose friends should produce no error") nFriends = 150 test, err = chooseRandomFriends(mockPeers, nFriends) friendsKeys := make([]string, 0, len(mockPeers)-1) for key, _ := range test { friendsKeys = append(friendsKeys, key) } assert.NoError(t, err, "(nFrineds > nPeers) Choose friends should produce no error") nFriends = 0 test, err = chooseRandomFriends(mockPeers, nFriends) assert.Error(t, err, "(nFriends < 0) Choose friends should produce an error") mockPeers = createMockPeers(0) nFriends = 10 _, err = chooseRandomFriends(mockPeers, nFriends) assert.Error(t, err, "(peers = 0) Choose friend should produce an error") mockPeers = createMockPeers(1) nFriends = 10 _, err = chooseRandomFriends(mockPeers, nFriends) assert.Error(t, err, "(peers = me) Choose friend should produce an error") mockPeers = createMockPeers(2) nFriends = 10 test, err = chooseRandomFriends(mockPeers, nFriends) assert.NoError(t, err, "(nFrineds == 2) Choose friends should produce no error") }
func CreateNode(name string, resources *res.Resource) { node_UUID, err := utils.GenerateUUID() if err != nil { log.WithField("err", err).Errorln("Error generating node UUID") } node_address := "http://" + network.Config().IpAddress + ":" + network.Config().Port config := cfg.NodeConfig{node_UUID, name, node_address, "", ""} nodeRes := cfg.NodeResources{ TotalCpus: resources.CPU.Total, TotalMemory: resources.Memory.Total, } node := cfg.Node{ Configuration: config, Active: false, Resources: nodeRes, } cfg.SetNode(node) }