Skip to content

Commit

Permalink
Misc (Go style) cleanups.
Browse files Browse the repository at this point in the history
Should be no functional change
  • Loading branch information
Harmen committed Dec 3, 2014
1 parent 74f6d7e commit 71cf586
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
12 changes: 5 additions & 7 deletions lib/clusternodesinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information.
// informatino can be one of jvm, process
// information can be one of jvm, process
func (c *Conn) AllNodesInfo() (NodeInfo, error) {
return c.NodesInfo([]string{"_all"}, "_all")
}
Expand All @@ -30,12 +30,10 @@ func (c *Conn) NodesInfo(information []string, nodes ...string) (NodeInfo, error
if err != nil {
return retval, err
}
if err == nil {
// marshall into json
jsonErr := json.Unmarshal(body, &retval)
if jsonErr != nil {
return retval, jsonErr
}
// marshall into json
jsonErr := json.Unmarshal(body, &retval)
if jsonErr != nil {
return retval, jsonErr
}
return retval, err
}
Expand Down
6 changes: 3 additions & 3 deletions lib/clusternodesinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestGetAll(t *testing.T) {
InitTests(true)
c := NewTestConn()
nodesInfo, err := c.AllNodesInfo()
//log.Println(out)
assert.T(t, err == nil, fmt.Sprintf("should not have gotten error, received :%v", err))
assert.T(t, nodesInfo.ClusterName == "elasticsearch", fmt.Sprintf("clustername should have been elasticsearch, received :%v", err))
assert.T(t, err == nil, fmt.Sprintf("should not have gotten error, received: %v", err))
clustername := "elasticsearch"
assert.T(t, nodesInfo.ClusterName == clustername, fmt.Sprintf("clustername should have been %q, received: %q", clustername, nodesInfo.ClusterName))
for _, node := range nodesInfo.Nodes {
assert.T(t, node.Settings != nil, fmt.Sprintf("Settings should not have been null"))
assert.T(t, node.OS != nil, fmt.Sprintf("OS should not have been null"))
Expand Down
2 changes: 0 additions & 2 deletions lib/clusterreroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (c *Conn) Reroute(dryRun bool, commands Commands) (ClusterHealthResponse, e
func dryRunOption(isDryRun bool) string {
if isDryRun {
return "dry_run"
} else {
return ""
}
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions lib/corebulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func XXXTestBulkUpdate(t *testing.T) {

date := time.Unix(1257894000, 0)
user := map[string]interface{}{
"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0), "count": 1,
"name": "smurfs", "age": 22, "date": date, "count": 1,
}

// Lets make sure the data is in the index ...
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestBulkSmallBatch(t *testing.T) {
c := NewTestConn()

date := time.Unix(1257894000, 0)
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": date}

// Now tests small batches
indexer := c.NewBulkIndexer(1)
Expand Down Expand Up @@ -185,7 +185,7 @@ func XXXTestBulkErrors(t *testing.T) {
go func() {
for i := 0; i < 20; i++ {
date := time.Unix(1257894000, 0)
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": date}
indexer.Index("users", "user", strconv.Itoa(i), "", &date, data, true)
}
}()
Expand Down
32 changes: 10 additions & 22 deletions lib/coretest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"log"
"net/http"
"testing"
"time"
)

Expand Down Expand Up @@ -78,21 +77,12 @@ func NewTestConn() *Conn {
return c
}

// dumb simple assert for testing, printing
// Assert(len(items) == 9, t, "Should be 9 but was %d", len(items))
func Assert(is bool, t *testing.T, format string, args ...interface{}) {
if is == false {
log.Printf(format, args...)
t.Fail()
}
}

// Wait for condition (defined by func) to be true, a utility to create a ticker
// checking every 100 ms to see if something (the supplied check func) is done
//
// WaitFor(func() bool {
// waitFor(func() bool {
// return ctr.Ct == 0
// },10)
// }, 10)
//
// @timeout (in seconds) is the last arg
func waitFor(check func() bool, timeoutSecs int) {
Expand All @@ -111,9 +101,6 @@ func waitFor(check func() bool, timeoutSecs int) {
}
}

func TestFake(t *testing.T) {
}

type GithubEvent struct {
Url string
Created time.Time `json:"created_at"`
Expand All @@ -132,7 +119,7 @@ func LoadTestData() {
req, err := c.NewRequest("POST", "/_bulk", "")
if err != nil {
errCt += 1
log.Fatalf("ERROR: ", err)
log.Fatalf("ERROR: %v", err)
return err
}
req.SetBody(buf)
Expand All @@ -147,7 +134,7 @@ func LoadTestData() {
if httpStatusCode != 200 {
log.Fatalf("Not 200! %d %q\n", httpStatusCode, buf.String())
}
return err
return nil
}
indexer.Start()
resp, err := http.Get("http://data.githubarchive.org/2012-12-10-15.json.gz")
Expand All @@ -170,11 +157,12 @@ func LoadTestData() {
h := md5.New()
for {
line, err := r.ReadBytes('\n')
if err != nil && err != io.EOF {
log.Println("FATAL: could not read line? ", err)
} else if err != nil {
indexer.Flush()
break
if err != nil {
if err == io.EOF {
indexer.Flush()
break
}
log.Fatalf("could not read line: %v", err)
}
if err := json.Unmarshal(line, &ge); err == nil {
// create an "ID"
Expand Down

0 comments on commit 71cf586

Please sign in to comment.