/usr/share/gocode/src/github.com/go-chef/chef/databag_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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | package chef
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestDataBagsService_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"bag1":"http://localhost/data/bag1", "bag2":"http://localhost/data/bag2"}`)
})
databags, err := client.DataBags.List()
if err != nil {
t.Errorf("DataBags.List returned error: %v", err)
}
want := &DataBagListResult{"bag1": "http://localhost/data/bag1", "bag2": "http://localhost/data/bag2"}
if !reflect.DeepEqual(databags, want) {
t.Errorf("DataBags.List returned %+v, want %+v", databags, want)
}
}
func TestDataBagsService_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"uri": "http://localhost/data/newdatabag"}`)
})
databag := &DataBag{Name: "newdatabag"}
response, err := client.DataBags.Create(databag)
if err != nil {
t.Errorf("DataBags.Create returned error: %v", err)
}
want := &DataBagCreateResult{URI: "http://localhost/data/newdatabag"}
if !reflect.DeepEqual(response, want) {
t.Errorf("DataBags.Create returned %+v, want %+v", response, want)
}
}
func TestDataBagsService_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/databag", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"name": "databag", "json_class": "Chef::DataBag", "chef_type": "data_bag"}`)
})
response, err := client.DataBags.Delete("databag")
if err != nil {
t.Errorf("DataBags.Delete returned error: %v", err)
}
want := &DataBag{
Name: "databag",
JsonClass: "Chef::DataBag",
ChefType: "data_bag",
}
if !reflect.DeepEqual(response, want) {
t.Errorf("DataBags.Delete returned %+v, want %+v", response, want)
}
}
func TestDataBagsService_ListItems(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/bag1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"item1":"http://localhost/data/bag1/item1", "item2":"http://localhost/data/bag1/item2"}`)
})
databags, err := client.DataBags.ListItems("bag1")
if err != nil {
t.Errorf("DataBags.ListItems returned error: %v", err)
}
want := &DataBagListResult{"item1": "http://localhost/data/bag1/item1", "item2": "http://localhost/data/bag1/item2"}
if !reflect.DeepEqual(databags, want) {
t.Errorf("DataBags.ListItems returned %+v, want %+v", databags, want)
}
}
func TestDataBagsService_GetItem(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/bag1/item1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"id":"item1", "stuff":"things"}`)
})
_, err := client.DataBags.GetItem("bag1", "item1")
if err != nil {
t.Errorf("DataBags.GetItem returned error: %v", err)
}
}
func TestDataBagsService_CreateItem(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/bag1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, ``)
})
dbi := map[string]string{
"id": "item1",
"foo": "test123",
}
err := client.DataBags.CreateItem("bag1", dbi)
if err != nil {
t.Errorf("DataBags.CreateItem returned error: %v", err)
}
}
func TestDataBagsService_DeleteItem(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/bag1/item1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, ``)
})
err := client.DataBags.DeleteItem("bag1", "item1")
if err != nil {
t.Errorf("DataBags.DeleteItem returned error: %v", err)
}
}
func TestDataBagsService_UpdateItem(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/bag1/item1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, ``)
})
dbi := map[string]string{
"id": "item1",
"foo": "test123",
}
err := client.DataBags.UpdateItem("bag1", "item1", dbi)
if err != nil {
t.Errorf("DataBags.UpdateItem returned error: %v", err)
}
}
func TestDataBagsService_DataBagListResultString(t *testing.T) {
e := &DataBagListResult{"bag1": "http://localhost/data/bag1", "bag2": "http://localhost/data/bag2"}
want := "bag1 => http://localhost/data/bag1\nbag2 => http://localhost/data/bag2\n"
if e.String() != want {
t.Errorf("DataBagListResult.String returned:\n%+v\nwant:\n%+v\n", e.String(), want)
}
}
|