This file is indexed.

/usr/share/gocode/src/github.com/go-chef/chef/search_test.go is in golang-github-go-chef-chef-dev 0.0.1+git20161023.60.deb8c38-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package chef

import (
	"fmt"
	"net/http"
	"reflect"
	"testing"
)

func TestSearch_Get(t *testing.T) {
	setup()
	defer teardown()

	mux.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, `{
			"node": "http://localhost:4000/search/node", 
			"role": "http://localhost:4000/search/role", 
			"client": "http://localhost:4000/search/client", 
			"users": "http://localhost:4000/search/users" 
		}`)
	})

	indexes, err := client.Search.Indexes()
	if err != nil {
		t.Errorf("Search.Get returned error: %+v", err)
	}
	wantedIdx := map[string]string{
		"node":   "http://localhost:4000/search/node",
		"role":   "http://localhost:4000/search/role",
		"client": "http://localhost:4000/search/client",
		"users":  "http://localhost:4000/search/users",
	}
	if !reflect.DeepEqual(indexes, wantedIdx) {
		t.Errorf("Search.Get returned %+v, want %+v", indexes, wantedIdx)
	}
}

func TestSearch_ExecDo(t *testing.T) {
	setup()
	defer teardown()

	mux.HandleFunc("/search/nodes", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, `{
	    "total": 1,
	    "start": 0,
	    "rows": [
	       {
	        "overrides": {"hardware_type": "laptop"},
	        "name": "latte",
	        "chef_type": "node",
	        "json_class": "Chef::Node",
	        "attributes": {"hardware_type": "laptop"},
	        "run_list": ["recipe[unicorn]"],
	        "defaults": {}
	       }
				 ]
		}`)
	})

	// test the fail case
	_, err := client.Search.NewQuery("foo", "failsauce")
	if err == nil {
		t.Errorf("Bad query wasn't caught")
	}

	// test the fail case
	_, err = client.Search.Exec("foo", "failsauce")
	if err == nil {
		t.Errorf("Bad query wasn't caught")
	}

	// test the positive case
	query, err := client.Search.NewQuery("nodes", "name:latte")
	if err != nil {
		t.Errorf("failed to create query")
	}

	// for now we aren't testing the result..
	_, err = query.Do(client)
	if err != nil {
		t.Errorf("Search.Exec failed", err)
	}

	_, err = client.Search.Exec("nodes", "name:latte")
	if err != nil {
		t.Errorf("Search.Exec failed", err)
	}

}