Skip to content

Commit

Permalink
fix(DB): fixing lock dates (#1982)
Browse files Browse the repository at this point in the history
Lock dates were getting written wrong into the overview.

Ref: SRX-FFMDKH
  • Loading branch information
miguel-crespo-fdc authored Sep 27, 2024
1 parent dede7c7 commit a2fd990
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,8 @@ func (h *DBHandler) DBWriteEnvironmentLockInternal(ctx context.Context, tx *sql.
return fmt.Errorf("DBWriteEnvironmentLockInternal unable to get transaction timestamp: %w", err)
}

envLock.Created = *now

jsonToInsert, err := json.Marshal(envLock.Metadata)
if err != nil {
return fmt.Errorf("could not marshal json data: %w", err)
Expand Down Expand Up @@ -3571,6 +3573,8 @@ func (h *DBHandler) DBWriteApplicationLockInternal(ctx context.Context, tx *sql.
return fmt.Errorf("DBWriteApplicationLockInternal unable to get transaction timestamp: %w", err)
}

appLock.Created = *now

jsonToInsert, err := json.Marshal(appLock.Metadata)
if err != nil {
return fmt.Errorf("could not marshal json data: %w", err)
Expand Down Expand Up @@ -3877,6 +3881,8 @@ func (h *DBHandler) DBWriteTeamLockInternal(ctx context.Context, tx *sql.Tx, tea
return fmt.Errorf("DBWriteTeamLockInternal unable to get transaction timestamp: %w", err)
}

teamLock.Created = *now

jsonToInsert, err := json.Marshal(teamLock.Metadata)
if err != nil {
return fmt.Errorf("could not marshal json data: %w", err)
Expand Down
54 changes: 49 additions & 5 deletions pkg/db/overview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestUpdateOverviewTeamLock(t *testing.T) {
DeployTime: "1",
},
Team: "team-123",
Locks: map[string]*api.Lock{
TeamLocks: map[string]*api.Lock{
"dev-lock": {
Message: "My lock on dev for my-team",
LockId: "dev-lock",
Expand Down Expand Up @@ -197,6 +197,17 @@ func TestUpdateOverviewTeamLock(t *testing.T) {
},
},
Team: "team-123",
Warnings: []*api.Warning{
{
WarningType: &api.Warning_UnusualDeploymentOrder{
UnusualDeploymentOrder: &api.UnusualDeploymentOrder{
UpstreamEnvironment: "staging",
ThisVersion: 12,
ThisEnvironment: "development",
},
},
},
},
},
},
GitRevision: "0",
Expand All @@ -222,6 +233,7 @@ func TestUpdateOverviewTeamLock(t *testing.T) {
}

for _, tc := range tcs {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
ctx := testutil.MakeTestContext()
Expand All @@ -232,20 +244,28 @@ func TestUpdateOverviewTeamLock(t *testing.T) {
if err != nil {
return err
}
opts := getOverviewIgnoredTypes()
latestOverview, err := dbHandler.ReadLatestOverviewCache(ctx, transaction) //sanity check
if err != nil {
return err
}
if diff := cmp.Diff(startingOverview, latestOverview, opts); diff != "" {
return fmt.Errorf("starting overviews mismatch (-want +got):\n%s", diff)
}
err = dbHandler.UpdateOverviewTeamLock(ctx, transaction, tc.NewTeamLock)
if err != nil {
if diff := cmp.Diff(tc.ExpectedError, err, cmpopts.EquateErrors()); diff != "" {
return fmt.Errorf("mismatch between errors (-want +got):\n%s", diff)
}
return nil
}
latestOverview, err := dbHandler.ReadLatestOverviewCache(ctx, transaction)
latestOverview, err = dbHandler.ReadLatestOverviewCache(ctx, transaction)
if err != nil {
return err
}
opts := getOverviewIgnoredTypes()

if diff := cmp.Diff(tc.ExcpectedOverview, latestOverview, opts); diff != "" {
return fmt.Errorf("mismatch (-want +got):\n%s", diff)
return fmt.Errorf("expected overview and last overview mismatch (-want +got):\n%s", diff)
}
tc.NewTeamLock.Deleted = true
err = dbHandler.UpdateOverviewTeamLock(ctx, transaction, tc.NewTeamLock)
Expand All @@ -257,7 +277,7 @@ func TestUpdateOverviewTeamLock(t *testing.T) {
return err
}
if diff := cmp.Diff(startingOverview, latestOverview, opts); diff != "" {
return fmt.Errorf("mismatch (-want +got):\n%s", diff)
return fmt.Errorf("starting overview and last overview mismatch (-want +got):\n%s", diff)
}
return nil
})
Expand Down Expand Up @@ -349,6 +369,17 @@ func TestUpdateOverviewEnvironmentLock(t *testing.T) {
},
},
Team: "team-123",
Warnings: []*api.Warning{
{
WarningType: &api.Warning_UnusualDeploymentOrder{
UnusualDeploymentOrder: &api.UnusualDeploymentOrder{
UpstreamEnvironment: "staging",
ThisVersion: 12,
ThisEnvironment: "development",
},
},
},
},
},
},
GitRevision: "0",
Expand All @@ -373,6 +404,7 @@ func TestUpdateOverviewEnvironmentLock(t *testing.T) {
}

for _, tc := range tcs {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
ctx := testutil.MakeTestContext()
Expand Down Expand Up @@ -780,6 +812,17 @@ func TestUpdateOverviewApplicationLock(t *testing.T) {
},
},
Team: "team-123",
Warnings: []*api.Warning{
{
WarningType: &api.Warning_UnusualDeploymentOrder{
UnusualDeploymentOrder: &api.UnusualDeploymentOrder{
UpstreamEnvironment: "staging",
ThisVersion: 12,
ThisEnvironment: "development",
},
},
},
},
},
},
GitRevision: "0",
Expand Down Expand Up @@ -822,6 +865,7 @@ func TestUpdateOverviewApplicationLock(t *testing.T) {
}

for _, tc := range tcs {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
ctx := testutil.MakeTestContext()
Expand Down

0 comments on commit a2fd990

Please sign in to comment.