/usr/share/gocode/src/github.com/go-chef/chef/cookbook_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 | package chef
import (
"fmt"
"io/ioutil"
"net/http"
//"os"
"testing"
)
const cookbookListResponseFile = "test/cookbooks_response.json"
const cookbookTestFile = "test/cookbook.json"
func TestCookbookList(t *testing.T) {
setup()
defer teardown()
file, err := ioutil.ReadFile(cookbookListResponseFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/cookbooks", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.Cookbooks.List()
if err != nil {
t.Error(err)
}
if data == nil {
t.Fatal("WTF we should have some data")
}
fmt.Println(data)
_, err = client.Cookbooks.ListAvailableVersions("3")
if err != nil {
t.Error(err)
}
_, err = client.Cookbooks.ListAvailableVersions("0")
if err != nil {
t.Error(err)
}
}
func TestCookbookListAvailableVersions_0(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/cookbooks", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "BAD FUCKING REQUEST", 503)
})
_, err := client.Cookbooks.ListAvailableVersions("2")
if err == nil {
t.Error("We expected this bad request to error", err)
}
}
func TestCookBookDelete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/cookbooks/good/1.1.1", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "")
})
mux.HandleFunc("/cookbooks/bad/1.1.1", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not Found", 404)
})
err := client.Cookbooks.Delete("bad", "1.1.1")
if err == nil {
t.Error("We expected this bad request to error", err)
}
err = client.Cookbooks.Delete("good", "1.1.1")
if err != nil {
t.Error(err)
}
}
func TestCookBookGet(t *testing.T) {
setup()
defer teardown()
cookbookVerionJSON := `{"url": "http://localhost:4000/cookbooks/apache2/5.1.0", "version": "5.1.0"}`
mux.HandleFunc("/cookbooks/good", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, cookbookVerionJSON)
})
mux.HandleFunc("/cookbooks/bad", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not Found", 404)
})
data, err := client.Cookbooks.Get("good")
if err != nil {
t.Error(err)
}
if data.Version != "5.1.0" {
t.Errorf("We expected '5.1.0' and got '%s'\n", data.Version)
}
_, err = client.Cookbooks.Get("bad")
if err == nil {
t.Error("We expected this bad request to error", err)
}
}
func TestCookBookGetAvailableVersions(t *testing.T) {
setup()
defer teardown()
cookbookVerionsJSON := `
{ "apache2": {
"url": "http://localhost:4000/cookbooks/apache2",
"versions": [
{"url": "http://localhost:4000/cookbooks/apache2/5.1.0",
"version": "5.1.0"},
{"url": "http://localhost:4000/cookbooks/apache2/4.2.0",
"version": "4.2.0"}
]
}}`
mux.HandleFunc("/cookbooks/good", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, cookbookVerionsJSON)
})
mux.HandleFunc("/cookbooks/bad", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not Found", 404)
})
data, err := client.Cookbooks.GetAvailableVersions("good", "3")
if err != nil {
t.Error(err)
}
fmt.Println(data)
}
func TestCookBookListAllRecipes(t *testing.T) {
setup()
defer teardown()
cookbookRecipesJSON := `
[
"apache2",
"apache2::mod_access_compat",
"apache2::mod_actions",
"apache2::mod_alias"
]`
mux.HandleFunc("/cookbooks/_recipes", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, cookbookRecipesJSON)
})
data, err := client.Cookbooks.ListAllRecipes()
if err != nil {
t.Error(err)
}
fmt.Println(data)
}
|