Skip to content

Commit 02555b1

Browse files
committed
Implement fake
1 parent 533e913 commit 02555b1

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

cli/templateversionarchive.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func (r *RootCmd) setArchiveTemplateVersion(archive bool) *clibase.Cmd {
7070
versions = append(versions, version)
7171
}
7272

73-
failed := 0
7473
for _, version := range versions {
7574
if version.Archived == archive {
7675
_, _ = fmt.Fprintln(
@@ -88,10 +87,6 @@ func (r *RootCmd) setArchiveTemplateVersion(archive bool) *clibase.Cmd {
8887
inv.Stdout, fmt.Sprintf("Version "+pretty.Sprint(cliui.DefaultStyles.Keyword, version.Name)+" "+pastVerb+" at "+cliui.Timestamp(time.Now())),
8988
)
9089
}
91-
92-
if failed > 0 {
93-
return xerrors.Errorf("failed on %d template versions", failed)
94-
}
9590
return nil
9691
},
9792
}
@@ -159,7 +154,6 @@ func (r *RootCmd) archiveTemplateVersions() *clibase.Cmd {
159154
return err
160155
}
161156

162-
failed := 0
163157
for _, template := range templates {
164158
resp, err := client.ArchiveTemplateVersions(ctx, template.ID, all.Value())
165159
if err != nil {
@@ -180,10 +174,6 @@ func (r *RootCmd) archiveTemplateVersions() *clibase.Cmd {
180174
)
181175
}
182176
}
183-
184-
if failed > 0 {
185-
return xerrors.Errorf("failed on %d templates", failed)
186-
}
187177
return nil
188178
},
189179
}

coderd/database/dbfake/dbfake.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,10 @@ func (q *FakeQuerier) ArchiveUnusedTemplateVersions(_ context.Context, arg datab
865865
// Not the latest
866866
continue
867867
}
868+
// Ignore deleted workspaces.
869+
if b.Transition == database.WorkspaceTransitionDelete {
870+
continue
871+
}
868872
latest[b.WorkspaceID] = latestBuild{
869873
Number: b.BuildNumber,
870874
Version: b.TemplateVersionID,
@@ -881,6 +885,11 @@ func (q *FakeQuerier) ArchiveUnusedTemplateVersions(_ context.Context, arg datab
881885

882886
var archived []uuid.UUID
883887
for i, v := range q.templateVersions {
888+
if arg.TemplateVersionID != uuid.Nil {
889+
if v.ID != arg.TemplateVersionID {
890+
continue
891+
}
892+
}
884893
if v.Archived {
885894
continue
886895
}
@@ -5336,7 +5345,16 @@ func (q *FakeQuerier) UnarchiveTemplateVersion(ctx context.Context, arg database
53365345
return err
53375346
}
53385347

5339-
panic("not implemented")
5348+
for i, v := range q.data.templateVersions {
5349+
if v.ID == arg.TemplateVersionID {
5350+
v.Archived = false
5351+
v.UpdatedAt = arg.UpdatedAt
5352+
q.data.templateVersions[i] = v
5353+
return nil
5354+
}
5355+
}
5356+
5357+
return sql.ErrNoRows
53405358
}
53415359

53425360
func (q *FakeQuerier) UpdateAPIKeyByID(_ context.Context, arg database.UpdateAPIKeyByIDParams) error {

coderd/database/queries/templateversions.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ FROM
195195
-- the build is outdated.
196196
NOT EXISTS (
197197
-- Return all "used" versions, where "used" is defined as being
198-
-- used by a latest workspace build.
198+
-- used by a latest workspace build.
199199
SELECT template_version_id FROM (
200200
SELECT
201201
DISTINCT ON (workspace_id) template_version_id, transition

0 commit comments

Comments
 (0)