mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Local App v2 :) * bind variables correctly * Play around with units * Port more commands over * Separate commands (1 per file) * `gitpod workspace delete` * Extract login * Show help text when run without a command * Fix login * `gitpod logout` * Simple logging * Remove unused import * Make host use consistent * Fix GetToken * Split distribution * 🤷♂️ * Fix paths 🤷🤦 * Change URL of binaries * Fix proxy binary handling Co-authored-by: Pudong <tianshi8650@gmail.com> * Improve logging * Change workspace list to be up-to-spec * `gitpod organizations list` * Simplify table code * `gitpod workspace get` * Created at * `gitpod organization get <id>` * Hide open for now * `workspace start --ssh` * `ws start --open` * server: OAuth client * Use OAuth app * logs * `gitpod workspace create` * Rename to follow singular noun semantics * Fix nil pointers in list and go cmds * `--field` for `gitpod organizations list` * `gitpod ws list --field` * Simplify some of the ws code * Unify WS data structure * Allow opening browser-based WSs * `gitpod workspace open` * Constants package to get rid of circular dependency issues * No config file by default * Guidance when missing in path * Fix local companion maybe 🤷♂️ * Create wait for start by default * Align scopes * KeychainName constant * Provide token via flag instead * Host in scope error lookup message * 🤷♂️ * Name for consistency * Editors in go client of papi * `gitpod workspace list-classes` * `gitpod config` * Infer orgs if applicable * Remove redundant error log * Retry mechanism for streaming * More useful error message for unauthed * README update * Allow `function:getTeam` * return org inference errors properly * Replace config with context * Fix config file path * Wrap up pretty printer * Name changes * Remove unused vars * 🇺🇸 * Update README * Fix login * [local-app] Add whoami command * [local-app] Add context management * Refactor common package * Harmonise output and formatting * Add error resolution support * Improve resolution printing * Add apology for system exceptions * Add class resolutions * Apologise more * Add unknown field resolution * Add better login context name * Make it build * `gitpod workspace list-editors` * Fix multiple ws IDs for `ws get` * Simplify open code * Update local-app README with usage instructions * Help for editor options * Remove unused config code * Call workspace ID field ID instead of workspace * Improve long format output * Fix whoami output * Streamline workspace listing * Introduce fancy intro * Improve set-context feedback * Remove common package * Add first unit test * Harmonise field order * Consistency across get commands * Consistency among list command aliases * Fix column name in whoami * Fix nil refs for empty hosts * Make prettyprint writer typesafe * Add resolutions for no token or no host found * Fix typo * Fix CI build * Properly record org ID on login * Print orgs in wide format * Added "workspace up" functionality back in but hidden * Make "Git" casing consistent https://english.stackexchange.com/questions/611711/tech-related-should-i-capitalize-the-word-git-in-this-context-or-not * Introduce workspace up intermediary * Fix proxied binary name --------- Co-authored-by: Pudong <tianshi8650@gmail.com> Co-authored-by: Christian Weichel (Chris) <chris@gitpod.io>
129 lines
3.0 KiB
Go
129 lines
3.0 KiB
Go
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gitpod-io/gitpod/components/public-api/go/client"
|
|
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
|
|
"github.com/gitpod-io/local-app/pkg/config"
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
type CommandTest struct {
|
|
Name string
|
|
Commandline []string
|
|
Config *config.Config
|
|
Expectation CommandTestExpectation
|
|
PrepServer func(mux *http.ServeMux)
|
|
}
|
|
|
|
type CommandTestExpectation struct {
|
|
Error string
|
|
Output string
|
|
}
|
|
|
|
func RunCommandTests(t *testing.T, tests []CommandTest) {
|
|
for _, test := range tests {
|
|
name := test.Name
|
|
if name == "" {
|
|
name = strings.Join(test.Commandline, " ")
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
actual := new(bytes.Buffer)
|
|
|
|
cfgfn, err := os.CreateTemp("", "local-app-test-cfg-*.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfgfn.Close()
|
|
defer os.Remove(cfgfn.Name())
|
|
|
|
if test.Config != nil {
|
|
if test.Config.ActiveContext == "test" {
|
|
mux := http.NewServeMux()
|
|
if test.PrepServer != nil {
|
|
test.PrepServer(mux)
|
|
}
|
|
|
|
apisrv := httptest.NewServer(mux)
|
|
t.Cleanup(apisrv.Close)
|
|
|
|
clnt, err := client.New(client.WithURL(apisrv.URL), client.WithCredentials("hello world"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rootTestingOpts.Client = clnt
|
|
|
|
test.Config.Contexts = map[string]*config.ConnectionContext{
|
|
"test": {
|
|
Host: &config.YamlURL{URL: &url.URL{Scheme: "https", Host: "testing"}},
|
|
Token: "hello world",
|
|
},
|
|
}
|
|
}
|
|
|
|
err = config.SaveConfig(cfgfn.Name(), test.Config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
rootCmd.SetArgs(test.Commandline)
|
|
rootCmd.SetOut(actual)
|
|
rootCmd.SetErr(actual)
|
|
rootTestingOpts.WriterOut = actual
|
|
rootOpts.ConfigLocation = cfgfn.Name()
|
|
err = rootCmd.Execute()
|
|
|
|
var act CommandTestExpectation
|
|
if err != nil {
|
|
act.Error = err.Error()
|
|
}
|
|
act.Output = actual.String()
|
|
|
|
if diff := cmp.Diff(test.Expectation, act); diff != "" {
|
|
t.Errorf("expectation mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// fixtureWorkspace returns a workspace fixture
|
|
func fixtureWorkspace() *v1.Workspace {
|
|
return &v1.Workspace{
|
|
WorkspaceId: "workspaceID",
|
|
OwnerId: "ownerId",
|
|
ProjectId: "projectId",
|
|
Context: &v1.WorkspaceContext{
|
|
ContextUrl: "contextUrl",
|
|
Details: &v1.WorkspaceContext_Git_{
|
|
Git: &v1.WorkspaceContext_Git{
|
|
Repository: &v1.WorkspaceContext_Repository{Name: "name", Owner: "owner"},
|
|
},
|
|
},
|
|
},
|
|
Description: "description",
|
|
Status: &v1.WorkspaceStatus{
|
|
Instance: &v1.WorkspaceInstance{
|
|
InstanceId: "instanceId",
|
|
WorkspaceId: "workspaceId",
|
|
Status: &v1.WorkspaceInstanceStatus{
|
|
StatusVersion: 1,
|
|
Phase: v1.WorkspaceInstanceStatus_PHASE_RUNNING,
|
|
Url: "url",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|