Add new Rebuild function

This commit is contained in:
JP Ungaretti 2022-10-08 00:04:45 +00:00
parent 4a81e46c1a
commit da91216c31
3 changed files with 33 additions and 0 deletions

View file

@ -66,6 +66,7 @@ type liveshareSession interface {
StartSharing(context.Context, string, int) (liveshare.ChannelID, error)
StartSSHServer(context.Context) (int, string, error)
StartSSHServerWithOptions(context.Context, liveshare.StartSSHServerOptions) (int, string, error)
Rebuild(context.Context) error
}
// Connects to a codespace using Live Share and returns that session

View file

@ -123,6 +123,20 @@ func (s *Session) StartJupyterServer(ctx context.Context) (int, string, error) {
return port, response.ServerUrl, nil
}
func (s *Session) Rebuild(ctx context.Context) error {
var success bool
err := s.rpc.do(ctx, "IEnvironmentConfigurationService.rebuildContainer", []string{}, &success)
if err != nil {
return fmt.Errorf("invoking rebuild RPC: %w", err)
}
if !success {
return fmt.Errorf("couldn't rebuild codespace")
} else {
return nil
}
}
// heartbeat runs until context cancellation, periodically checking whether there is a
// reason to keep the connection alive, and if so, notifying the Live Share host to do so.
// Heartbeat ensures it does not send more than one request every "interval" to ratelimit

View file

@ -399,6 +399,24 @@ func TestSessionHeartbeat(t *testing.T) {
}
}
func TestRebuild(t *testing.T) {
getSharedServers := func(conn *jsonrpc2.Conn, req *jsonrpc2.Request) (interface{}, error) {
return true, nil
}
testServer, session, err := makeMockSession(
livesharetest.WithService("IEnvironmentConfigurationService.rebuildContainer", getSharedServers),
)
if err != nil {
t.Fatalf("creating mock session: %v", err)
}
defer testServer.Close()
err = session.Rebuild(context.Background())
if err != nil {
t.Fatalf("rebuilding codespace over mock session: %v", err)
}
}
type mockLogger struct {
sync.Mutex
buf *bytes.Buffer