Skip to content

Commit

Permalink
test(common): add tests for validator
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Aug 6, 2023
1 parent c602eb4 commit b6292be
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions common/validator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package common

import "testing"

func TestOptions_Validate_ValidConfig(t *testing.T) {
opt := &Options{
Port: 8080,
Destination: "example.com",
Config: &Config{
Path: "config.yaml",
Format: "yaml",
},
TLS: nil,
}

err := opt.Validate()
if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}
}

func TestOptions_Validate_EmptyDestination(t *testing.T) {
opt := &Options{
Port: 8080,
Destination: "",
Config: &Config{
Path: "config.yaml",
Format: "yaml",
},
TLS: nil,
}

err := opt.Validate()
if err != ErrDestAddressEmpty {
t.Errorf("Expected ErrDestAddressEmpty, but got: %v", err)
}
}

func TestOptions_Validate_InvalidConfigFormat(t *testing.T) {
opt := &Options{
Port: 8080,
Destination: "example.com",
Config: &Config{
Path: "config.json",
Format: "xml",
},
TLS: nil,
}

err := opt.Validate()
if err != ErrCfgFileFormatInv {
t.Errorf("Expected ErrCfgFileFormatInv, but got: %v", err)
}
}

func TestOptions_Validate_MissingConfigPathAndFormat(t *testing.T) {
opt := &Options{
Port: 8080,
Destination: "example.com",
Config: &Config{},
TLS: nil,
}

err := opt.Validate()
if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}
}

func TestOptions_Validate_NilOptions(t *testing.T) {
opt := &Options{}

err := opt.Validate()
if err != ErrDestAddressEmpty {
t.Errorf("Expected ErrDestAddressEmpty, but got: %v", err)
}
}

0 comments on commit b6292be

Please sign in to comment.