-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Schmidt
committed
Jul 15, 2024
1 parent
808189b
commit a8208ed
Showing
5 changed files
with
159 additions
and
38 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,80 @@ | ||
//go:build unit | ||
|
||
package flags | ||
|
||
import ( | ||
"asvec/tests" | ||
"testing" | ||
) | ||
|
||
func TestCredentialsFlag_Set(t *testing.T) { | ||
// Test setting user and password | ||
flag := CredentialsFlag{} | ||
err := flag.Set("username:password") | ||
if err != nil { | ||
t.Errorf("Error setting credentials: %v", err) | ||
} | ||
|
||
// Test setting user only | ||
err = flag.Set("username") | ||
if err != nil { | ||
t.Errorf("Error setting user: %v", err) | ||
} | ||
|
||
// Test setting password only | ||
err = flag.Set(":password") | ||
if err != nil { | ||
t.Errorf("Error setting password: %v", err) | ||
} | ||
|
||
// Test setting empty value | ||
err = flag.Set("") | ||
if err != nil { | ||
t.Errorf("Error setting empty value: %v", err) | ||
} | ||
} | ||
|
||
func TestCredentialsFlag_Type(t *testing.T) { | ||
flag := CredentialsFlag{} | ||
expected := "<user>[:<pass>]" | ||
actual := flag.Type() | ||
|
||
if expected != actual { | ||
t.Errorf("Expected type '%s', got '%s'", expected, actual) | ||
} | ||
} | ||
|
||
func TestCredentialsFlag_String(t *testing.T) { | ||
// Test string representation with user and password | ||
flag := CredentialsFlag{ | ||
User: StringOptionalFlag{Val: tests.GetStrPtr("username")}, | ||
Password: StringOptionalFlag{Val: tests.GetStrPtr("password")}, | ||
} | ||
str := flag.String() | ||
expected := "username:password" | ||
if str != expected { | ||
t.Errorf("Expected string '%s', got '%s'", expected, str) | ||
} | ||
|
||
// Test string representation with user only | ||
flag = CredentialsFlag{ | ||
User: StringOptionalFlag{Val: tests.GetStrPtr("username")}, | ||
Password: StringOptionalFlag{}, | ||
} | ||
str = flag.String() | ||
expected = "username:<nil>" | ||
if str != expected { | ||
t.Errorf("Expected string '%s', got '%s'", expected, str) | ||
} | ||
|
||
// Test string representation with empty values | ||
flag = CredentialsFlag{ | ||
User: StringOptionalFlag{}, | ||
Password: StringOptionalFlag{}, | ||
} | ||
str = flag.String() | ||
expected = "<nil>:<nil>" | ||
if str != expected { | ||
t.Errorf("Expected string '%s', got '%s'", expected, str) | ||
} | ||
} |
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,42 @@ | ||
//go:build unit | ||
|
||
package flags | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestUnixTimestampFlag_Set(t *testing.T) { | ||
var flag UnixTimestampFlag | ||
testTimestamp := "1609459200" // Corresponds to 2021-01-01 00:00:00 UTC | ||
expectedTime := time.Unix(1609459200, 0) | ||
|
||
err := flag.Set(testTimestamp) | ||
if err != nil { | ||
t.Errorf("Failed to set UnixTimestampFlag: %v", err) | ||
} | ||
|
||
if !flag.Time().Equal(expectedTime) { | ||
t.Errorf("Expected time %v, got %v", expectedTime, flag.Time()) | ||
} | ||
} | ||
|
||
func TestUnixTimestampFlag_String(t *testing.T) { | ||
expectedString := "1609459200" | ||
var flag UnixTimestampFlag | ||
flag.Set(expectedString) | ||
|
||
if flag.String() != expectedString { | ||
t.Errorf("Expected string representation %s, got %s", expectedString, flag.String()) | ||
} | ||
} | ||
|
||
func TestUnixTimestampFlag_Type(t *testing.T) { | ||
var flag UnixTimestampFlag | ||
expectedType := "unix-timestamp (sec)" | ||
|
||
if flag.Type() != expectedType { | ||
t.Errorf("Expected type %s, got %s", expectedType, flag.Type()) | ||
} | ||
} |
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
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