Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/go/user_test.go
2498 views
1
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package protocol
6
7
import "testing"
8
9
func TestGetSSOEmail(t *testing.T) {
10
u := &User{
11
Identities: []*Identity{
12
{
13
PrimaryEmail: "[email protected]",
14
LastSigninTime: "2022-01-01T00:00:00Z",
15
},
16
{
17
PrimaryEmail: "[email protected]",
18
LastSigninTime: "2022-03-01T00:00:00Z",
19
},
20
{
21
PrimaryEmail: "[email protected]",
22
LastSigninTime: "2022-02-01T00:00:00Z",
23
},
24
{
25
PrimaryEmail: "[email protected]",
26
LastSigninTime: "",
27
},
28
},
29
}
30
31
expectedEmail := "[email protected]"
32
actualEmail := u.GetSSOEmail()
33
34
if actualEmail != expectedEmail {
35
t.Errorf("Expected SSO email to be %s, but got %s", expectedEmail, actualEmail)
36
}
37
}
38
func TestGetRandomEmail(t *testing.T) {
39
u := &User{
40
Identities: []*Identity{
41
{
42
PrimaryEmail: "",
43
LastSigninTime: "",
44
},
45
{
46
PrimaryEmail: "[email protected]",
47
LastSigninTime: "",
48
Deleted: true,
49
},
50
{
51
PrimaryEmail: "[email protected]",
52
LastSigninTime: "",
53
},
54
{
55
PrimaryEmail: "[email protected]",
56
LastSigninTime: "2022-03-01T00:00:00Z",
57
},
58
{
59
PrimaryEmail: "[email protected]",
60
LastSigninTime: "2022-02-01T00:00:00Z",
61
},
62
{
63
PrimaryEmail: "[email protected]",
64
LastSigninTime: "",
65
},
66
},
67
}
68
69
expectedEmail := "[email protected]"
70
actualEmail := u.GetRandomEmail()
71
72
if actualEmail != expectedEmail {
73
t.Errorf("Expected random email to be %s, but got %s", expectedEmail, actualEmail)
74
}
75
}
76
77