Skip to content

Commit

Permalink
User: add unit test for GetShortName - do not convert to upper case
Browse files Browse the repository at this point in the history
  • Loading branch information
TerraTalpi committed Aug 30, 2021
1 parent d6600ba commit 19da171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion User.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (u User) GetShortName() string {
if len(supn) != 2 {
return u.UserPrincipalName
}
return strings.ToUpper(supn[0])
return supn[0]
}

// GetFullName returns the full name in that format: <firstname> <lastname>
Expand Down
13 changes: 13 additions & 0 deletions User_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ func TestUser_UpdateUser(t *testing.T) {
}
}

func TestUser_GetShortName(t *testing.T) {
// test a normal case
testuser := User{UserPrincipalName: "[email protected]"}
if testuser.GetShortName() != "dumpty" {
t.Errorf("user.GetShortName() should return \"dumpty\", but returns: %v", testuser.GetShortName())
}
// test a case that actually should never happen... but we all know murphy
testuser = User{UserPrincipalName: "alice"}
if testuser.GetShortName() != "alice" {
t.Errorf("user.GetShortName() should return \"alice\", but returns: %v", testuser.GetShortName())
}
}

func TestUser_GetFullName(t *testing.T) {
testuser := User{GivenName: "Bob", Surname: "Rabbit"}
wanted := fmt.Sprintf("%v %v", testuser.GivenName, testuser.Surname)
Expand Down

0 comments on commit 19da171

Please sign in to comment.