commit 717a9e7823638c994c6620883fcee2ef98da294b from: Oliver Lowe date: Wed Feb 02 04:44:52 2022 UTC Keep test data in version control While here also don't log messages in testing unless there's an error. commit - dca9442c1f7da187028aaaf66f2ebf7c34d6a863 commit + 717a9e7823638c994c6620883fcee2ef98da294b blob - 158940542dafee9f573ab77e19866a464b348d17 blob + 981b6c85fc470333686a0a81cd94f54d8da819e3 --- host_test.go +++ host_test.go @@ -26,29 +26,27 @@ func TestHostMarshal(t *testing.T) { if err != nil { t.Fatal(err) } - t.Log(string(p)) got := make(map[string]interface{}) if err := json.Unmarshal(p, &got); err != nil { t.Fatal(err) } if !reflect.DeepEqual(want, got) { - t.Fail() + t.Error("want", want, "got", got) } - t.Log("want", want, "got", got) } func TestHostUnmarshal(t *testing.T) { want := Host{ - Name: "example.com", + Name: "VuS9jZ8u.example.org", Address: "", - Groups: []string{"example"}, + Groups: []string{}, State: HostDown, StateType: StateSoft, CheckCommand: "hostalive", - DisplayName: "example.com", + DisplayName: "VuS9jZ8u.example.org", Acknowledgement: false, } - f, err := os.Open("testdata/hosts.json") + f, err := os.Open("testdata/objects/hosts/VuS9jZ8u.example.org") if err != nil { t.Fatal(err) } @@ -57,16 +55,8 @@ func TestHostUnmarshal(t *testing.T) { if err != nil { t.Fatal(err) } - var got Host - for _, r := range resp.Results { - h := r.(Host) - if h.Name == "example.com" { - got = h - break - } - } + got := resp.Results[0].(Host) if !reflect.DeepEqual(want, got) { - t.Fail() + t.Errorf("want %+v, got %+v", want, got) } - t.Logf("want %+v, got %+v", want, got) } blob - 589b4df48e8ac7c1a0e2bd753a75152e33f1dacd blob + 66fe315b19691f68e64f8f90ba8971310d7fffbb --- service_test.go +++ service_test.go @@ -8,7 +8,7 @@ import ( ) func TestServiceUnmarshal(t *testing.T) { - f, err := os.Open("testdata/services.json") + f, err := os.Open("testdata/objects/services/9p.io!http") if err != nil { t.Fatal(err) } @@ -25,7 +25,7 @@ func TestServiceUnmarshal(t *testing.T) { CheckCommand: "http", DisplayName: "http", LastCheckResult: CheckResult{ - Output: "HTTP OK: HTTP/1.1 200 OK - 1714 bytes in 0.703 second response time ", + Output: "HTTP OK: HTTP/1.1 200 OK - 1714 bytes in 1.083 second response time ", }, } var got Service @@ -35,9 +35,8 @@ func TestServiceUnmarshal(t *testing.T) { } } if !reflect.DeepEqual(want, got) { - t.Fail() + t.Errorf("want %+v, got %+v", want, got) } - t.Logf("want %+v, got %+v", want, got) } func TestServiceMarshal(t *testing.T) { @@ -59,7 +58,6 @@ func TestServiceMarshal(t *testing.T) { } got := string(b) if want != got { - t.Fail() + t.Error("want", want, "got", got) } - t.Log("want", want, "got", got) } blob - /dev/null blob + 7f7cfd4e0aebe84b39cce6a4b2852c1f6db1e453 (mode 644) --- /dev/null +++ testdata/objects/hosts/VuS9jZ8u.example.org @@ -0,0 +1,91 @@ +{ + "results": [ + { + "attrs": { + "__name": "VuS9jZ8u.example.org", + "acknowledgement": 0, + "acknowledgement_expiry": 0, + "acknowledgement_last_change": 0, + "action_url": "", + "active": true, + "address": "", + "address6": "", + "check_attempt": 1, + "check_command": "hostalive", + "check_interval": 300, + "check_period": "", + "check_timeout": null, + "command_endpoint": "", + "display_name": "VuS9jZ8u.example.org", + "downtime_depth": 0, + "enable_active_checks": true, + "enable_event_handler": true, + "enable_flapping": false, + "enable_notifications": true, + "enable_passive_checks": true, + "enable_perfdata": true, + "event_command": "", + "executions": null, + "flapping": false, + "flapping_current": 0, + "flapping_ignore_states": null, + "flapping_last_change": 0, + "flapping_threshold": 0, + "flapping_threshold_high": 30, + "flapping_threshold_low": 25, + "force_next_check": false, + "force_next_notification": false, + "groups": [], + "ha_mode": 0, + "handled": false, + "icon_image": "", + "icon_image_alt": "", + "last_check": -1, + "last_check_result": null, + "last_hard_state": 1, + "last_hard_state_change": 1641607863.315727, + "last_reachable": true, + "last_state": 1, + "last_state_change": 1641607863.315727, + "last_state_down": 0, + "last_state_type": 0, + "last_state_unreachable": 0, + "last_state_up": 0, + "max_check_attempts": 3, + "name": "VuS9jZ8u.example.org", + "next_check": 1641614556.854738, + "next_update": 1641614856.854738, + "notes": "", + "notes_url": "", + "original_attributes": null, + "package": "_api", + "paused": false, + "previous_state_change": 1641607863.315727, + "problem": false, + "retry_interval": 60, + "severity": 16, + "source_location": { + "first_column": 0, + "first_line": 1, + "last_column": 33, + "last_line": 1, + "path": "/var/lib/icinga2/api/packages/_api/19602f4d-849c-4589-a9fe-cc1c71790f3c/conf.d/hosts/VuS9jZ8u.example.org.conf" + }, + "state": 1, + "state_type": 0, + "templates": [ + "VuS9jZ8u.example.org" + ], + "type": "Host", + "vars": null, + "version": 1641608345.032706, + "volatile": false, + "zone": "alpine.olowe.co" + }, + "joins": {}, + "meta": {}, + "name": "VuS9jZ8u.example.org", + "type": "Host" + } + ] +} blob - /dev/null blob + ac22c0888275fc037a4a55e539a81940cf5a34e4 (mode 644) --- /dev/null +++ testdata/objects/services/9p.io!http @@ -0,0 +1,127 @@ +{ + "results": [ + { + "attrs": { + "__name": "9p.io!http", + "acknowledgement": 0, + "acknowledgement_expiry": 0, + "acknowledgement_last_change": 0, + "action_url": "", + "active": true, + "check_attempt": 1, + "check_command": "http", + "check_interval": 60, + "check_period": "", + "check_timeout": null, + "command_endpoint": "", + "display_name": "http", + "downtime_depth": 0, + "enable_active_checks": true, + "enable_event_handler": true, + "enable_flapping": false, + "enable_notifications": true, + "enable_passive_checks": true, + "enable_perfdata": true, + "event_command": "", + "executions": null, + "flapping": false, + "flapping_current": 0, + "flapping_ignore_states": null, + "flapping_last_change": 1642495283.418991, + "flapping_threshold": 0, + "flapping_threshold_high": 30, + "flapping_threshold_low": 25, + "force_next_check": false, + "force_next_notification": false, + "groups": [], + "ha_mode": 0, + "handled": true, + "host_name": "9p.io", + "icon_image": "", + "icon_image_alt": "", + "last_check": 1642496528.415804, + "last_check_result": { + "active": true, + "check_source": "alpine.olowe.co", + "command": [ + "/usr/lib/monitoring-plugins/check_http", + "-I", + "9p.io" + ], + "execution_end": 1642496528.415702, + "execution_start": 1642496527.310383, + "exit_status": 0, + "output": "HTTP OK: HTTP/1.1 200 OK - 1714 bytes in 1.083 second response time ", + "performance_data": [ + "time=1.082636s;;;0.000000;10.000000", + "size=1714B;;;0" + ], + "schedule_end": 1642496528.415804, + "schedule_start": 1642496527.016395, + "scheduling_source": "alpine.olowe.co", + "state": 0, + "ttl": 0, + "type": "CheckResult", + "vars_after": { + "attempt": 1, + "reachable": false, + "state": 0, + "state_type": 1 + }, + "vars_before": { + "attempt": 1, + "reachable": false, + "state": 0, + "state_type": 1 + } + }, + "last_hard_state": 0, + "last_hard_state_change": 1642494988.994212, + "last_reachable": false, + "last_state": 0, + "last_state_change": 1642494988.994212, + "last_state_critical": 1642494810.489733, + "last_state_ok": 1642496528.415702, + "last_state_type": 1, + "last_state_unknown": 1642494869.390854, + "last_state_unreachable": 1642496528.415702, + "last_state_warning": 1642494987.196548, + "max_check_attempts": 5, + "name": "http", + "next_check": 1642496587.835849, + "next_update": 1642496650.634463, + "notes": "", + "notes_url": "", + "original_attributes": null, + "package": "_etc", + "paused": false, + "previous_state_change": 1642494988.994212, + "problem": false, + "retry_interval": 30, + "severity": 0, + "source_location": { + "first_column": 1, + "first_line": 55, + "last_column": 20, + "last_line": 55, + "path": "/etc/icinga2/conf.d/ye.conf" + }, + "state": 0, + "state_type": 1, + "templates": [ + "http", + "generic-service" + ], + "type": "Service", + "vars": null, + "version": 0, + "volatile": false, + "zone": "" + }, + "joins": {}, + "meta": {}, + "name": "9p.io!http", + "type": "Service" + } + ] +} blob - /dev/null blob + 24d38a09aaba3202d282123dd02b26cce1d5d930 (mode 644) --- /dev/null +++ testdata/objects/users/test @@ -0,0 +1,42 @@ +{ + "results": [ + { + "attrs": { + "__name": "test", + "active": true, + "display_name": "test", + "email": "test@example.com", + "enable_notifications": true, + "groups": [], + "ha_mode": 0, + "last_notification": 0, + "name": "test", + "original_attributes": null, + "package": "_etc", + "pager": "", + "paused": false, + "period": "", + "source_location": { + "first_column": 1, + "first_line": 56, + "last_column": 18, + "last_line": 56, + "path": "/etc/icinga2/conf.d/ye.conf" + }, + "states": null, + "templates": [ + "test" + ], + "type": "User", + "types": null, + "vars": null, + "version": 0, + "zone": "" + }, + "joins": {}, + "meta": {}, + "name": "test", + "type": "User" + } + ] +} blob - 24d38a09aaba3202d282123dd02b26cce1d5d930 (mode 644) blob + /dev/null --- testdata/users.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "results": [ - { - "attrs": { - "__name": "test", - "active": true, - "display_name": "test", - "email": "test@example.com", - "enable_notifications": true, - "groups": [], - "ha_mode": 0, - "last_notification": 0, - "name": "test", - "original_attributes": null, - "package": "_etc", - "pager": "", - "paused": false, - "period": "", - "source_location": { - "first_column": 1, - "first_line": 56, - "last_column": 18, - "last_line": 56, - "path": "/etc/icinga2/conf.d/ye.conf" - }, - "states": null, - "templates": [ - "test" - ], - "type": "User", - "types": null, - "vars": null, - "version": 0, - "zone": "" - }, - "joins": {}, - "meta": {}, - "name": "test", - "type": "User" - } - ] -} blob - 3a95ff592e00bab4eecd60fbd241a469c224e6c4 blob + 9b67b01b2c6089f55ee6c002f992a2b07d971139 --- user_test.go +++ user_test.go @@ -9,7 +9,7 @@ import ( func TestUser(t *testing.T) { want := User{Name: "test", Email: "test@example.com", Groups: []string{}} - f, err := os.Open("testdata/users.json") + f, err := os.Open("testdata/objects/users/test") if err != nil { t.Fatal(err) }