Skip to content

Commit e6f01e3

Browse files
committed
test
1 parent 85bb481 commit e6f01e3

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

components/gitpod-db/go/dbtest/personal_access_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func NewPersonalAccessToken(t *testing.T, record db.PersonalAccessToken) db.PersonalAccessToken {
1919
t.Helper()
2020

21-
now := time.Now().UTC()
21+
now := time.Now().UTC().Round(time.Millisecond)
2222
tokenID := uuid.New()
2323

2424
result := db.PersonalAccessToken{

components/gitpod-db/go/personal_access_token.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ func (s *Scopes) Scan(src any) error {
125125
if !ok {
126126
return errors.New("src value cannot cast to []byte")
127127
}
128+
129+
if len(bytes) == 0 {
130+
*s = nil
131+
return nil
132+
}
133+
128134
*s = strings.Split(string(bytes), ",")
129135
return nil
130136
}
137+
131138
func (s Scopes) Value() (driver.Value, error) {
132139
if len(s) == 0 {
133140
return "", nil

components/public-api-server/pkg/apiv1/tokens_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
connect "github.com/bufbuild/connect-go"
1414
"github.com/gitpod-io/gitpod/common-go/experiments"
1515
"github.com/gitpod-io/gitpod/common-go/experiments/experimentstest"
16+
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
1617
"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"
1718
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
1819
"github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"
@@ -122,14 +123,27 @@ func TestTokensService_ListPersonalAccessTokens(t *testing.T) {
122123
require.Equal(t, connect.CodePermissionDenied, connect.CodeOf(err))
123124
})
124125

125-
t.Run("unimplemented when feature flag enabled", func(t *testing.T) {
126-
serverMock, _, client := setupTokensService(t, withTokenFeatureEnabled)
126+
t.Run("lists first page of results, when no pagination preference specified", func(t *testing.T) {
127+
serverMock, dbConn, client := setupTokensService(t, withTokenFeatureEnabled)
127128

128129
serverMock.EXPECT().GetLoggedInUser(gomock.Any()).Return(user, nil)
129130

130-
_, err := client.ListPersonalAccessTokens(context.Background(), connect.NewRequest(&v1.ListPersonalAccessTokensRequest{}))
131-
132-
require.Equal(t, connect.CodeUnimplemented, connect.CodeOf(err))
131+
tokens := dbtest.CreatePersonalAccessTokenRecords(t, dbConn,
132+
dbtest.NewPersonalAccessToken(t, db.PersonalAccessToken{
133+
UserID: uuid.MustParse(user.ID),
134+
}),
135+
dbtest.NewPersonalAccessToken(t, db.PersonalAccessToken{
136+
UserID: uuid.MustParse(user.ID),
137+
}),
138+
)
139+
140+
response, err := client.ListPersonalAccessTokens(context.Background(), connect.NewRequest(&v1.ListPersonalAccessTokensRequest{}))
141+
require.NoError(t, err)
142+
143+
requireEqualProto(t, &v1.ListPersonalAccessTokensResponse{
144+
Tokens: personalAccessTokensToAPI(tokens),
145+
TotalResults: 2,
146+
}, response.Msg)
133147
})
134148
}
135149

0 commit comments

Comments
 (0)