Skip to content

Commit

Permalink
Update README.md/create acceptance tests (bfraser#3)
Browse files Browse the repository at this point in the history
* initial commit to implement grafana_folder resource type

* add required parameters for grafana objects

* remove references to dashboard objects (dashboard used as template)

* update tests

* remove whitespace for rubocop

* rubocop fixes

* fix global var assignment clause logic

* update README.md/created acceptance test for grafana_folder resource
  • Loading branch information
alexconrey authored Apr 8, 2019
1 parent a448ec0 commit b13f3d5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ If you are using a sub-path for the Grafana API, you will need to set the `grafa
- `grafana_datasource`
- `grafana_organization`
- `grafana_user`
- `grafana_folder`

For instance, if your sub-path is `/grafana`, the `grafana_api_path` must
be set to `/grafana/api`. Do not add a trailing `/` (slash) at the end of the value.
Expand Down Expand Up @@ -640,6 +641,21 @@ grafana_plugin { 'grafana-simple-json-datasource':
}
```

##### `grafana_folder`

Creates and manages Grafana folders via the API.

The following example creates a folder named 'folder1':
```puppet
grafana_folder { 'folder1':
grafana_url => 'http://localhost:3000',
grafana_api_path => '/grafana/api',
grafana_user => 'admin',
grafana_password => '5ecretPassw0rd',
}
```
`grafana_api_path` is only required if using sub-paths for the API

##### `grafana::user`

Creates and manages a global grafana user via the API.
Expand Down
63 changes: 63 additions & 0 deletions spec/acceptance/grafana_folder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'spec_helper_acceptance'

describe 'grafana_folder' do
context 'create folder resource' do
it 'runs successfully' do
pp = <<-EOS
class { 'grafana':
cfg => {
security => {
admin_user => 'admin',
admin_password => 'admin'
}
}
}
grafana_folder { 'example-folder':
ensure => present,
grafana_url => 'http://localhost:3000',
grafana_user => 'admin',
grafana_password => 'admin',
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

it 'has the folder' do
shell('curl --user admin:admin http://localhost:3000/api/folders') do |f|
expect(f.stdout).to match(%r{example-folder})
end
end
end

context 'destroy folder resource' do
it 'runs successfully' do
pp = <<-EOS
class { 'grafana':
cfg => {
security => {
admin_user => 'admin',
admin_password => 'admin'
}
}
}
grafana_folder { 'example-folder':
ensure => absent,
grafana_url => 'http://localhost:3000',
grafana_user => 'admin',
grafana_password => 'admin',
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

it 'does not have the folder' do
shell('curl --user admin:admin http://localhost:3000/api/folders') do |f|
expect(f.stdout).not_to match(%r{example-folder})
end
end
end
end

0 comments on commit b13f3d5

Please sign in to comment.