Skip to content

Commit

Permalink
Create check yaml loading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Oct 5, 2022
1 parent 989f924 commit c599512
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/catalog_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
defmodule Wanda.CatalogTest do
use ExUnit.Case

alias Wanda.Catalog

alias Wanda.Catalog.{
Check,
Condition,
Expectation,
Fact,
Value
}

describe "checks catalog" do
test "should load a check from a yaml file properly" do
assert %Check{
id: "expect_check",
name: "Test check",
severity: :critical,
facts: [
%Fact{
name: "corosync_token_timeout",
gatherer: "corosync",
argument: "totem.token"
}
],
values: [],
expectations: [
%Expectation{
name: "timeout",
type: :expect,
expression: "corosync_token_timeout == 30000"
}
]
} = Catalog.get_check("expect_check")
end

test "should load a critical as default severity" do
assert %Check{severity: :critical} = Catalog.get_check("expect_same_check")
end

test "should load a warning severity" do
assert %Check{severity: :warning} = Catalog.get_check("warning_severity_check")
end

test "should load checks with values" do
assert %Check{
values: [
%Value{
conditions: [
%Condition{expression: "some_expression", value: 10},
%Condition{expression: "some_other_expression", value: 15}
],
default: 5,
name: "expected_value"
},
%Value{
conditions: [
%Condition{expression: "some_third_expression", value: 5}
],
default: 10,
name: "expected_higher_value"
}
]
} = Catalog.get_check("with_values_check")
end
end
end
30 changes: 30 additions & 0 deletions test/fixtures/catalog/with_values_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
id: with_values
name: Test check
group: Test
description: |
Just a check
remediation: |
## Remediation
Remediation text
facts:
- name: jedi
gatherer: wandalorian
argument: -o
values:
- name: expected_value
default: 5
conditions:
- value: 10
when: some_expression
- value: 15
when: some_other_expression
- name: expected_higher_value
default: 10
conditions:
- value: 5
when: some_third_expression
expectations:
- name: some_expectation
expect: jedi == values.expected_value
- name: some_other_expectation
expect: jedi > values.expected_higher_value

0 comments on commit c599512

Please sign in to comment.