-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(common): add tests for validator
- Loading branch information
1 parent
c602eb4
commit b6292be
Showing
1 changed file
with
77 additions
and
0 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
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) | ||
} | ||
} |