Skip to content

Commit

Permalink
test_: add test for VerifyDatabasePasswordV2
Browse files Browse the repository at this point in the history
  • Loading branch information
qfrank committed Sep 23, 2024
1 parent c4158e1 commit 42eba58
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
9 changes: 7 additions & 2 deletions protocol/requests/verify_database_password_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ type VerifyDatabasePasswordV2 struct {
}

// Validate checks the validity of the VerifyDatabasePasswordV2 request.
var (
ErrVerifyDatabasePasswordV2EmptyKeyUID = errors.New("verify-database-password-v2: KeyUID cannot be empty")
ErrVerifyDatabasePasswordV2EmptyPassword = errors.New("verify-database-password-v2: Password cannot be empty")
)

func (v *VerifyDatabasePasswordV2) Validate() error {
if v.KeyUID == "" {
return errors.New("verify-database-password-v2: KeyUID cannot be empty")
return ErrVerifyDatabasePasswordV2EmptyKeyUID
}
if v.Password == "" {
return errors.New("verify-database-password-v2: Password cannot be empty")
return ErrVerifyDatabasePasswordV2EmptyPassword
}
return nil
}
36 changes: 36 additions & 0 deletions protocol/requests/verify_database_password_v2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package requests

import "testing"

func TestVerifyDatabasePasswordV2Validate(t *testing.T) {
tests := []struct {
name string
request VerifyDatabasePasswordV2
wantErr error
}{
{
name: "Empty KeyUID",
request: VerifyDatabasePasswordV2{KeyUID: "", Password: "password"},
wantErr: ErrVerifyDatabasePasswordV2EmptyKeyUID,
},
{
name: "Empty Password",
request: VerifyDatabasePasswordV2{KeyUID: "keyuid", Password: ""},
wantErr: ErrVerifyDatabasePasswordV2EmptyPassword,
},
{
name: "Valid Request",
request: VerifyDatabasePasswordV2{KeyUID: "keyuid", Password: "password"},
wantErr: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.request.Validate()
if err != tt.wantErr {
t.Errorf("VerifyDatabasePasswordV2.Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 42eba58

Please sign in to comment.