Skip to content

Commit 52e4bb7

Browse files
author
Laurie T. Malau
committed
facepalm
1 parent e36ab71 commit 52e4bb7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ package dbtest
66

77
import (
88
"context"
9+
"database/sql/driver"
10+
"errors"
911
"fmt"
12+
"strings"
1013
"time"
1114

1215
"github.com/google/uuid"
@@ -21,7 +24,7 @@ type PersonalAccessToken struct {
2124
Hash string `gorm:"column:hash;type:varchar;size:255;" json:"hash"`
2225
Name string `gorm:"column:name;type:varchar;size:255;" json:"name"`
2326
Description string `gorm:"column:description;type:varchar;size:255;" json:"description"`
24-
Scopes []string `gorm:"column:scopes;type:text;size:65535;" json:"scopes"`
27+
Scopes Scopes `gorm:"column:scopes;type:text;size:65535;" json:"scopes"`
2528
ExpirationTime time.Time `gorm:"column:expirationTime;type:timestamp;" json:"expirationTime"`
2629
CreatedAt time.Time `gorm:"column:createdAt;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"createdAt"`
2730
LastModified time.Time `gorm:"column:_lastModified;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"_lastModified"`
@@ -30,6 +33,8 @@ type PersonalAccessToken struct {
3033
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
3134
}
3235

36+
type Scopes []string
37+
3338
// TableName sets the insert table name for this struct type
3439
func (d *PersonalAccessToken) TableName() string {
3540
return "d_b_personal_access_token"
@@ -73,3 +78,18 @@ func CreateToken(ctx context.Context, conn *gorm.DB, req PersonalAccessToken) (P
7378

7479
return token, nil
7580
}
81+
82+
func (s *Scopes) Scan(src any) error {
83+
bytes, ok := src.([]byte)
84+
if !ok {
85+
return errors.New("src value cannot cast to []byte")
86+
}
87+
*s = strings.Split(string(bytes), ",")
88+
return nil
89+
}
90+
func (s Scopes) Value() (driver.Value, error) {
91+
if len(s) == 0 {
92+
return nil, nil
93+
}
94+
return strings.Join(s, ","), nil
95+
}

components/common-go/db/dbtest/personal_access_token_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ func TestPersonalAccessToken_Get(t *testing.T) {
2929
LastModified: time.Now(),
3030
}
3131

32-
conn.Create(token)
33-
read := PersonalAccessToken{ID: token.ID}
34-
conn.First(read)
32+
tx := conn.Create(token)
33+
require.NoError(t, tx.Error)
3534

3635
result, err := GetToken(context.Background(), conn, token.ID)
3736
require.NoError(t, err)

0 commit comments

Comments
 (0)