Debian Codegraph @

parser/status_test.go

raw symbols SCIP
1 package parserscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.25 testing/"
5 "timescip-go gomod github.com/golang/go/src go1.25 time/"
6 )
7
8 func TestParseStatusscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/TestParseStatus().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
9 sample := `
10 BIRD 2.17.1 ready.
11 BIRD 2.17.1
12 Router ID is 10.72.0.164
13 Hostname is store-blob-pp014
14 Current server time is 2025-08-21 10:27:57.219
15 Last reboot on 2025-07-31 14:23:03.232
16 Last reconfiguration on 2025-08-07 09:53:19.531
17 Daemon is up and running
18 `
19
20 s := ParseStatusscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/ParseStatus().([]byte(sample))
21
22 if s.Versionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#Version. != "2.17.1" {
23 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected Version=2.17.1, got %q", s.Versionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#Version.)
24 }
25 if s.RouterIDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#RouterID. != "10.72.0.164" {
26 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected RouterID=10.72.0.164, got %q", s.RouterIDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#RouterID.)
27 }
28
29 expectedServerTime := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2025, 8, 21, 10, 27, 57, 219000000, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.)
30 if !s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime..Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(expectedServerTime) {
31 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected ServerTime=%v, got %v", expectedServerTime, s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime.)
32 }
33
34 expectedLastReboot := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2025, 7, 31, 14, 23, 3, 232000000, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.)
35 if !s.LastRebootscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReboot..Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(expectedLastReboot) {
36 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected LastReboot=%v, got %v", expectedLastReboot, s.LastRebootscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReboot.)
37 }
38
39 expectedLastReconfig := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2025, 8, 7, 9, 53, 19, 531000000, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.)
40 if !s.LastReconfigscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReconfig..Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(expectedLastReconfig) {
41 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected LastReconfig=%v, got %v", expectedLastReconfig, s.LastReconfigscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReconfig.)
42 }
43
44 if !s.DaemonUpscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#DaemonUp. {
45 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected DaemonUp=true, got false")
46 }
47 }
48
49 func TestParseStatusMissingFieldsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/TestParseStatusMissingFields().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
50 sample := `
51 BIRD 2.17.1
52 Daemon is down
53 `
54
55 s := ParseStatusscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/ParseStatus().([]byte(sample))
56
57 if s.Versionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#Version. != "2.17.1" {
58 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected Version=2.17.1, got %q", s.Versionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#Version.)
59 }
60 if s.DaemonUpscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#DaemonUp. {
61 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected DaemonUp=false, got true")
62 }
63
64 // Other fields should be zero-values
65 if !s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime..IsZeroscip-go gomod github.com/golang/go/src go1.25 time/Time#IsZero().() {
66 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected ServerTime zero, got %v", s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime.)
67 }
68 if !s.LastRebootscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReboot..IsZeroscip-go gomod github.com/golang/go/src go1.25 time/Time#IsZero().() {
69 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected LastReboot zero, got %v", s.LastRebootscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReboot.)
70 }
71 if !s.LastReconfigscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReconfig..IsZeroscip-go gomod github.com/golang/go/src go1.25 time/Time#IsZero().() {
72 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected LastReconfig zero, got %v", s.LastReconfigscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#LastReconfig.)
73 }
74 if s.RouterIDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#RouterID. != "" {
75 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected RouterID empty, got %q", s.RouterIDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#RouterID.)
76 }
77 }
78
79 func TestParseStatusMalformedTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/TestParseStatusMalformedTime().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
80 sample := `
81 BIRD 2.17.1
82 Current server time is not-a-time
83 Daemon is up
84 `
85
86 s := ParseStatusscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/ParseStatus().([]byte(sample))
87
88 if !s.DaemonUpscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#DaemonUp. {
89 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected DaemonUp=true, got false")
90 }
91 if !s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime..IsZeroscip-go gomod github.com/golang/go/src go1.25 time/Time#IsZero().() {
92 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected ServerTime zero due to parse error, got %v", s.ServerTimescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/parser`/Status#ServerTime.)
93 }
94 }