-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(syslogexporter): Change config validation to follow OTC standards…
… and fix timestamp format issues
- Loading branch information
1 parent
d226b6f
commit 1f63adf
Showing
11 changed files
with
168 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package syslogexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
cfg *Config | ||
err string | ||
}{ | ||
{ | ||
name: "invalid Port", | ||
cfg: &Config{ | ||
Port: 515444, | ||
Endpoint: "host.domain.com", | ||
Format: "rfc5424", | ||
Protocol: "udp", | ||
}, | ||
err: "Unsupported Port: Port is required, must be in the range 1-65535", | ||
}, | ||
|
||
{ | ||
name: "invalid Endpoint", | ||
cfg: &Config{ | ||
Port: 514, | ||
Endpoint: "", | ||
Format: "rfc5424", | ||
Protocol: "udp", | ||
}, | ||
err: "Invalid FQDN: Endpoint is required, must be a valid FQDN", | ||
}, | ||
|
||
{ | ||
name: "unsupported Protocol", | ||
cfg: &Config{ | ||
Port: 514, | ||
Endpoint: "host.domain.com", | ||
Format: "rfc5424", | ||
Protocol: "ftp", | ||
}, | ||
err: "Unsupported protocol: Protocol is required, only tcp/udp supported", | ||
}, | ||
{ | ||
name: "Unsupported Format", | ||
cfg: &Config{ | ||
Port: 514, | ||
Endpoint: "host.domain.com", | ||
Protocol: "udp", | ||
Format: "rfc", | ||
}, | ||
err: "Unsupported format: Only rfc5424 and rfc3164 supported", | ||
}, | ||
} | ||
for _, testInstance := range tests { | ||
t.Run(testInstance.name, func(t *testing.T) { | ||
err := testInstance.cfg.Validate() | ||
if testInstance.err != "" { | ||
assert.EqualError(t, err, testInstance.err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.