Skip to content

Commit

Permalink
Merge branch 'go-chef:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kalroy authored Mar 10, 2022
2 parents d6206c8 + c7df6ae commit f38a26e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion role.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Role struct {
ChefType string `json:"chef_type,omitempty"`
DefaultAttributes interface{} `json:"default_attributes,omitempty"`
Description string `json:"description"`
EnvRunList EnvRunList `json:"env_run_lists"`
EnvRunList EnvRunList `json:"env_run_lists,omitempty"`
JsonClass string `json:"json_class,omitempty"`
OverrideAttributes interface{} `json:"override_attributes,omitempty"`
RunList RunList `json:"run_list"`
Expand Down
6 changes: 3 additions & 3 deletions test_chef_server/Berksfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ DEPENDENCIES
metadata: true

GRAPH
chef-ingredient (3.1.3)
chef-server (5.5.3)
chef-ingredient (3.4.0)
chef-server (5.6.0)
chef-ingredient (>= 2.1.10)
line (2.9.0)
line (4.4.4)
test_chef_server (0.1.0)
chef-server (>= 0.0.0)
line (>= 0.0.0)
6 changes: 5 additions & 1 deletion test_chef_server/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ verifier:
name: inspec

platforms:
- name: ubuntu-18.04
- name: ubuntu-20.04
driver_config:
customize:
cpus: 4
memory: 4096

suites:
- name: default
Expand Down
2 changes: 2 additions & 0 deletions test_chef_server/recipes/chef_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Create an organization
execute 'create test organization' do
command '/opt/opscode/bin/chef-server-ctl org-create test test_org'
ignore_failure true
not_if '/opt/opscode/bin/chef-server-ctl org-list | grep test'
end

execute 'get the ssl certificate for the chef server' do
command 'knife ssl fetch'
ignore_failure true
not_if { ::File.exist? '/root/.chef/trusted_certs/localhost' }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
its('stderr') { should match(%r{^Issue getting nothere: GET https://testhost/organizations/test/roles/nothere: 404}) }
its('stderr') { should_not match(/error|no such file|cannot find|not used|undefined/) }
its('stdout') { should match(%r{^Added role1 uri => https://testhost/organizations/test/roles/role1}) }
its('stdout') { should match(%r{^Added roleNR uri => https://testhost/organizations/test/roles/roleNR}) }
its('stdout') { should match(%r{^List roles after adding role1 role1 => https://testhost/organizations/test/roles/role1}) }
its('stdout') { should match(/^Get role1 &\{Name:role1 ChefType:role DefaultAttributes:map\[(?=.*git_repo:here.git)(?=.*users:\[root moe\]).*\] Description:Test role EnvRunList:map\[(?=.*en2:\[recipe\[foo2\]\]).*(?=.*en1:\[recipe\[foo1\] recipe\[foo2\]\]).*JsonClass:Chef::Role OverrideAttributes:map\[env:map\[(?=.*mine:ample)(?=.*yours:full).*\]\] RunList:\[recipe\[foo\] recipe\[baz\] role\[banana\]\]\}/) }
its('stdout') { should match(/^Update role1 &\{Name:role1 ChefType:role DefaultAttributes:map\[(?=.*git_repo:here.git)(?=.*users:\[root moe\]).*\] Description:Changed Role EnvRunList:map\[(?=.*en1:\[recipe\[foo1\] recipe\[foo2\]\]).*(?=.*en2:\[recipe\[foo2\]\]).*JsonClass:Chef::Role OverrideAttributes:map\[env:map\[(?=.*mine:ample)(?=.*yours:full).*\]\] RunList:\[recipe\[foo\] recipe\[baz\] role\[banana\]\]\}/) }
Expand Down
1 change: 1 addition & 0 deletions testapi/bin/role
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ BASE=$(dirname $0)

. ${BASE}/setup
. ${BASE}/creds

go run ${BASE}/../testcase/testcase.go role ${CHEFUSER} ${KEYFILE} ${CHEFORGANIZATIONURL} ${SSLBYPASS}
24 changes: 24 additions & 0 deletions testapi/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func Role() {
}
fmt.Printf("Added role1 %+v\n", roleAdd)

// Build a stucture to define a role
roleNR := create_role_norunlist()
// Add a new role
roleAdd, err = client.Roles.Create(&roleNR)
if err != nil {
fmt.Fprintln(os.Stderr, "Issue adding roleNR:", err)
}
fmt.Printf("Added roleNR %+v\n", roleAdd)

// Add role again
roleAdd, err = client.Roles.Create(&role1)
if err != nil {
Expand Down Expand Up @@ -87,6 +96,12 @@ func Role() {
}
fmt.Printf("Delete role1 %+v\n", err)

err = client.Roles.Delete("roleNR")
if err != nil {
fmt.Fprintln(os.Stderr, "Issue deleting roleNR", err)
}
fmt.Printf("Delete roleNR %+v\n", err)

_, err = client.Environments.Delete("en1")

// Final list of roles
Expand Down Expand Up @@ -140,3 +155,12 @@ func create_role1() chef.Role {
}
return role1
}

func create_role_norunlist() chef.Role {
role1 := chef.Role{
Name: "roleNR",
Description: "Test role",
RunList: []string{"recipe[foo]", "recipe[baz]", "role[banana]"},
}
return role1
}

0 comments on commit f38a26e

Please sign in to comment.