github.com/go-chef/chef@v0.30.1/testapi/association_setup.go (about)

     1  // Test the go-chef/chef chef server api /organization/:org/user and /organization/:org/association_requests
     2  // endpoints against a live server
     3  package testapi
     4  
     5  import (
     6  	"fmt"
     7  	"github.com/go-chef/chef"
     8  	"os"
     9  )
    10  
    11  // association_setup exercise the chef server api
    12  func AssociationSetup() {
    13  	client := Client(nil)
    14  
    15  	// Create a user
    16  	var usr chef.User
    17  	usr = chef.User{UserName: "usrinvite",
    18  		Email:       "usrauth@domain.io",
    19  		FirstName:   "usr",
    20  		LastName:    "invite",
    21  		DisplayName: "Userauth Fullname",
    22  		Password:    "Logn12ComplexPwd#",
    23  	}
    24  	createUser(client, usr)
    25  
    26  	usr = chef.User{UserName: "usr2invite",
    27  		Email:       "usr22auth@domain.io",
    28  		FirstName:   "usr22",
    29  		LastName:    "invite",
    30  		DisplayName: "User22auth Fullname",
    31  		Password:    "Logn12ComplexPwd#",
    32  	}
    33  	createUser(client, usr)
    34  
    35  	usr = chef.User{UserName: "usradd",
    36  		Email:       "usradd@domain.io",
    37  		FirstName:   "usr",
    38  		LastName:    "add",
    39  		DisplayName: "UserAdd Fullname",
    40  		Password:    "Logn12ComplexPwd#",
    41  	}
    42  	createUser(client, usr)
    43  
    44  }
    45  
    46  // createUser uses the chef server api to create a single user
    47  func createUser(client *chef.Client, user chef.User) chef.UserResult {
    48  	usrResult, err := client.Users.Create(user)
    49  	if err != nil {
    50  		fmt.Fprintln(os.Stderr, "Issue creating user:", err)
    51  	}
    52  	return usrResult
    53  }