Skip to content

Commit

Permalink
Moving folders around so structure is more readable
Browse files Browse the repository at this point in the history
Signed-off-by: tyler-ball <[email protected]>
  • Loading branch information
tyler-ball authored and MarkGibbons committed Apr 8, 2020
1 parent 3d9cf8f commit e12d853
Show file tree
Hide file tree
Showing 97 changed files with 433 additions and 407 deletions.
29 changes: 29 additions & 0 deletions examples/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'll add some doc about testing and development. I'll take the request as a really good suggestion.
Thanks

Basic ideas for adding an endpoint, assume you will repeat this process and each step multiple times:

Design the data structures for a new end point

Create go tests for each func.

Write the go code.

Add examples to exercise the functions in the chefapi_examples cookbook.

Create go code to call the functions. See the files in go-chef/chef/examples/cmd. Many times extra setup is required.
Create a shell script to call the go code. See the files in go-chef/chef/examples/bin.
Write Inspec tests to verify the output. Be aware that go map output does not alway have consistent ordering. The matching regex structures are rarely fun to write.
Commit the go-chef/chef (api client go code at least) changes to a branch and push to GitHub. The chefapi.rb recipe would need to be updated to pull from the correct repo.
kitchen converge. - installs the code, spins up a chef server to test against
kitchen login - run the /bin commands and iterate on fixing the code. Both cmd code and chef client code. kitchen converge will install cmd and bin file changes without committing and pushing to GitHub. Changes to the chef api client code need to be committed, pushed and kitchen converge run again to get the changes installed.
While logged in to the virtual box image try adding "-tags" debug the bin command. Example
go run -tags debug ${BASE}/../cmd/client/clients.go ${CHEFUSER} ${KEYFILE} ${CHEFORGANIZATIONURL} ${SSLBYPASS} will produce output that shows the real request body returned from the chef server. Note what you passed in and what you got back. Send updates for the documentation to https://github.com/chef/chef-web-docs
After things work ok. Create an inspec test for the endpoint that calls the bin command for the endpoint. Run kitchen verify to run the full set of integration tests.
Run cookstyle -a in the go-chef/chef/examples/chefapi_examples directory

Run go fmt in the go-chef/chef directory

See if any documentation needs to be updated, check to see if any of the scattered TODOs are now now.

Commit and PR
2 changes: 1 addition & 1 deletion examples/bin
15 changes: 0 additions & 15 deletions examples/chefapi_examples/Berksfile.lock

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

43 changes: 0 additions & 43 deletions examples/chefapi_examples/recipes/setup.rb

This file was deleted.

File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/chefapi_test/Testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Global
https://testhost

## Organization specific
https://testhost/organization/test/*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
package main

import (
"chefapi_test/testapi"
"fmt"
"chefapi_test/testapi"
"github.com/go-chef/chef"
"os"
)

"github.com/go-chef/chef"
)

// main Exercise the chef server api
func main() {
client := testapi.Client()

// Build stuctures to invite users
invite := chef.Request {
invite := chef.Request{
User: "usrinvite",
}
invite2 := chef.Request {
invite2 := chef.Request{
User: "usr2invite",
}
invitemissing := chef.Request {
invitemissing := chef.Request{
User: "nouser",
}
add1 := chef.AddNow {
add1 := chef.AddNow{
Username: "usradd",
}

Expand All @@ -49,7 +49,7 @@ func main() {
fmt.Printf("Invited user %+v %+v\n", invitemissing, out)

// Find a pending invitation by user name
id, err := client.Associations.InviteId("usr2invite")
id, err := client.Associations.InviteId("usr2invite")
if err != nil {
fmt.Fprintf(os.Stderr, "Issue finding an invitation for usr2invite %+v\n", err)
}
Expand All @@ -58,7 +58,7 @@ func main() {
// Accept the invite for invite2
// outa, err := client.Associations.AcceptInvite(id)
// if err != nil {
// fmt.Fprintf(os.Stderr, "Issue accepting the invitation %+v\n", err)
// fmt.Fprintf(os.Stderr, "Issue accepting the invitation %+v\n", err)
// }
// fmt.Printf("Accept invitation %+v\n", outa)

Expand All @@ -71,33 +71,33 @@ func main() {
fmt.Printf("Invitation list %+v\n", outl)

// Delete the invitations by id
for _, in := range outl {
outd, err := client.Associations.DeleteInvite(in.Id)
if err != nil {
fmt.Fprintf(os.Stderr, "Issue deleting an invitation for %s %+v\n", in.UserName, err)
}
fmt.Printf("Deleted invitation %s for %s %+v\n", in.Id, in.UserName, outd)
}
for _, in := range outl {
outd, err := client.Associations.DeleteInvite(in.Id)
if err != nil {
fmt.Fprintf(os.Stderr, "Issue deleting an invitation for %s %+v\n", in.UserName, err)
}
fmt.Printf("Deleted invitation %s for %s %+v\n", in.Id, in.UserName, outd)
}

// Add a user to the test organization
// Add a user to the test organization
err = client.Associations.Add(add1)
if err != nil {
fmt.Fprintf(os.Stderr, "Issue adding user usradd: %+v\n", err)
}
fmt.Printf("User added: %+v\n", add1)
// List the users
// List the users
ulist, err := client.Associations.List()
if err != nil {
fmt.Fprintf(os.Stderr, "Issue listing the users: %+v\n", err)
}
fmt.Printf("Users list: %+v\n", ulist)
// Get the user details
// Get the user details
uget, err := client.Associations.Get("usradd")
if err != nil {
fmt.Fprintf(os.Stderr, "Issue getting user details: %+v\n", err)
}
fmt.Printf("User details: %+v\n", uget)
// Delete a user for the organization
// Delete a user for the organization
udel, err := client.Associations.Get("usradd")
if err != nil {
fmt.Fprintf(os.Stderr, "Issue deleting usradd: %+v\n", err)
Expand Down
30 changes: 30 additions & 0 deletions examples/chefapi_test/cmd/association/association_cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Test the go-chef/chef chef server api /organization/:org/user and /organization/:org/association_requests
// endpoints against a live server
//
package main

import (
"chefapi_test/testapi"
"fmt"
"os"

"github.com/go-chef/chef"
)

// main Exercise the chef server api
func main() {
client := testapi.Client()
deleteUser(client, "usrinvite")
deleteUser(client, "usr2invite")
deleteUser(client, "usradd")
}

// deleteUser uses the chef server api to delete a single user
func deleteUser(client *chef.Client, name string) (err error) {
err = client.Users.Delete(name)
if err != nil {
fmt.Fprintln(os.Stderr, "Issue deleting org:", err)
}
return
}
56 changes: 56 additions & 0 deletions examples/chefapi_test/cmd/association/association_setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Test the go-chef/chef chef server api /organization/:org/user and /organization/:org/association_requests
// endpoints against a live server
//
package main

import (
"chefapi_test/testapi"
"fmt"
"github.com/go-chef/chef"
"os"
)

// main Exercise the chef server api
func main() {
client := testapi.Client()

// Create a user
var usr chef.User
usr = chef.User{UserName: "usrinvite",
Email: "[email protected]",
FirstName: "usr",
LastName: "invite",
DisplayName: "Userauth Fullname",
Password: "Logn12ComplexPwd#",
}
createUser(client, usr)

usr = chef.User{UserName: "usr2invite",
Email: "[email protected]",
FirstName: "usr22",
LastName: "invite",
DisplayName: "User22auth Fullname",
Password: "Logn12ComplexPwd#",
}
createUser(client, usr)

usr = chef.User{UserName: "usradd",
Email: "[email protected]",
FirstName: "usr",
LastName: "add",
DisplayName: "UserAdd Fullname",
Password: "Logn12ComplexPwd#",
}
createUser(client, usr)

}

// createUser uses the chef server api to create a single user
func createUser(client *chef.Client, user chef.User) chef.UserResult {
usrResult, err := client.Users.Create(user)
if err != nil {
fmt.Fprintln(os.Stderr, "Issue creating user:", err)
}
return usrResult
}
Loading

0 comments on commit e12d853

Please sign in to comment.