Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix convert
  • Loading branch information
defelmnq committed Jan 4, 2025
commit 5824e5f0869f0afeb59e1e213a7107f789b18d84
24 changes: 20 additions & 4 deletions codersdk/agentsdk/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,15 @@
return codersdk.WorkspaceApp{}, xerrors.Errorf("unknown app health: %v (%q)", protoApp.Health, protoApp.Health.String())
}

openIn := codersdk.WorkspaceAppOpenIn(strings.ToLower(protoApp.OpenIn.String()))
if _, ok := codersdk.MapWorkspaceAppOpenIns[openIn]; !ok {
var openIn codersdk.WorkspaceAppOpenIn
switch protoApp.OpenIn {
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["SLIM_WINDOW"]):
openIn = codersdk.WorkspaceAppOpenInSlimWindow
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["WINDOW"]):
openIn = codersdk.WorkspaceAppOpenInWindow
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["TAB"]):
openIn = codersdk.WorkspaceAppOpenInTab
default:
return codersdk.WorkspaceApp{}, xerrors.Errorf("unknown app open in option: %v (%q)", protoApp.OpenIn, protoApp.OpenIn.String())
}

Expand Down Expand Up @@ -273,10 +280,19 @@
if !ok {
return nil, xerrors.Errorf("unknown health %s", a.Health)
}
openIn, ok := proto.WorkspaceApp_OpenIn_value[strings.ToUpper(string(a.OpenIn))]
if !ok {

var openIn proto.WorkspaceApp_OpenIn
switch a.OpenIn {
case "slim-window":
openIn = proto.WorkspaceApp_SLIM_WINDOW
case "window":
openIn = proto.WorkspaceApp_WINDOW
case "tab":
openIn = proto.WorkspaceApp_TAB
default:
return nil, xerrors.Errorf("unknown open_in %s", a.OpenIn)
}

return &proto.WorkspaceApp{
Id: a.ID[:],
Url: a.URL,
Expand All @@ -295,7 +311,7 @@
},
Health: proto.WorkspaceApp_Health(health),
Hidden: a.Hidden,
OpenIn: proto.WorkspaceApp_OpenIn(openIn),

Check failure on line 314 in codersdk/agentsdk/convert.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions codersdk/agentsdk/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestManifest(t *testing.T) {
},
Health: codersdk.WorkspaceAppHealthHealthy,
Hidden: false,
OpenIn: codersdk.WorkspaceAppOpenInSlimWindow,
},
{
ID: uuid.New(),
Expand All @@ -64,6 +65,7 @@ func TestManifest(t *testing.T) {
},
Health: codersdk.WorkspaceAppHealthInitializing,
Hidden: true,
OpenIn: codersdk.WorkspaceAppOpenInTab,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed the test inputs and it passes with no futher changes? Are we not checking for this in the test?
Should we also add a test with an invalid value for OpenIn?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed will add some more tests 👀

},
},
DERPMap: &tailcfg.DERPMap{
Expand Down
Loading