Skip to content

Commit

Permalink
finish up sandbox testing
Browse files Browse the repository at this point in the history
  • Loading branch information
spheromak committed Aug 23, 2014
1 parent 9506443 commit 7bed7f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
7 changes: 5 additions & 2 deletions examples/sandboxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func main() {

// build a client
client, err := chef.NewClient(&chef.Config{
Name: "foo",
Key: string(key),
Name: "foo",
Key: string(key),
// goiardi is on port 4545 by default. chef-zero is 8889
BaseURL: "http://localhost:4545",
})
if err != nil {
Expand All @@ -54,6 +55,7 @@ func main() {
postResp, err := client.Sandboxes.Post(sums)
if err != nil {
fmt.Println("error making request: ", err)
os.Exit(1)
}

// Dump the the server response data
Expand Down Expand Up @@ -92,6 +94,7 @@ func main() {
sandbox, err := client.Sandboxes.Put(postResp.ID)
if err != nil {
fmt.Println("Error commiting sandbox: ", err.Error())
os.Exit(1)
}

// and heres yer commited sandbox
Expand Down
39 changes: 34 additions & 5 deletions sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"net/http"
_ "reflect"
"testing"

"github.com/davecgh/go-spew/spew"
. "github.com/smartystreets/goconvey/convey"
)

// generate random data for sandbox
Expand Down Expand Up @@ -48,20 +47,50 @@ func TestSandboxesPost(t *testing.T) {
files[hashstr] = data
sums = append(sums, hashstr)
}

// post the new sums/files to the sandbox
res, err := client.Sandboxes.Post(sums)
_, err := client.Sandboxes.Post(sums)
if err != nil {
t.Errorf("Snadbox Post error making request: ", err)
}
// TODO: Need to compare result here not just ensure it works
spew.Dump(res)
}

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

mux.HandleFunc("/sandboxes/f1c560ccb472448e9cfb31ff98134247", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{
"guid": "123",
"name": "123",
"CreateionTime": "2014-08-23 18:13:37",
"is_completed": true,
"uri": "https://127.0.0.1/sandboxes/f1c560ccb472448e9cfb31ff98134247",
"checksums": [
"3124216defe5849089a577ffefb0bb05",
"e06ddfa07ca97c80c368d08e189b928a",
"eb65444f8adeb11c56cf0df201a07cb4"
]
}`)
})

sandbox, err := client.Sandboxes.Put("f1c560ccb472448e9cfb31ff98134247")
if err != nil {
t.Errorf("Snadbox Put error making request: ", err)
}

expected := Sandbox{
ID: "123",
Name: "123",
Completed: true,
Checksums: []string{
"3124216defe5849089a577ffefb0bb05",
"e06ddfa07ca97c80c368d08e189b928a",
"eb65444f8adeb11c56cf0df201a07cb4",
},
}

Convey("Sandbox Equality", t, func() {
So(sandbox, ShouldResemble, expected)
})
}

0 comments on commit 7bed7f5

Please sign in to comment.