Merge pull request #1774 from Molecule-AI/fix/orgtoken-mocks-clean

fix: sync orgtoken.Validate mocks to 3-column scan pattern
This commit is contained in:
Hongming Wang 2026-04-24 13:04:08 +00:00 committed by GitHub
commit bf62a68fef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,6 +36,11 @@ func TestWorkspaceAuth_ValidOrgToken_SetsOrgIDContext(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-org-abc", "tok_test", "00000000-0000-0000-0000-000000000001"))
// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-org-abc").
WillReturnResult(sqlmock.NewResult(0, 1))
r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
v, exists := c.Get("org_id")
@ -84,6 +89,11 @@ func TestWorkspaceAuth_ValidOrgToken_OrgIDNULL_DoesNotSetContext(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-old-xyz", "tok_old_", nil))
// Best-effort last_used_at update after Validate succeeds (even for NULL org_id).
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-old-xyz").
WillReturnResult(sqlmock.NewResult(0, 1))
r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
_, exists := c.Get("org_id")
@ -216,6 +226,11 @@ func TestWorkspaceAuth_OrgToken_DBRowScanError_DoesNotPanic(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-ok", "tok_tok_", "00000000-0000-0000-0000-000000000099"))
// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-ok").
WillReturnResult(sqlmock.NewResult(0, 1))
r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
// org_id key may or may not be set — either is acceptable here.
@ -255,6 +270,11 @@ func TestWorkspaceAuth_OrgToken_SetsAllContextKeys(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-full", "tok_fu_", expectedOrgID))
// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-full").
WillReturnResult(sqlmock.NewResult(0, 1))
r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
id, ok := c.Get("org_token_id")