mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Add version command * Restructure config package * Bring back config get and config set * Support login host without protocol scheme * Add autoupdate functionality * Generate update manifest during build * Better update failure behavior * Add latest to version command * Add version update command * Use cannonical semver form
68 lines
1.9 KiB
Go
68 lines
1.9 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 (
|
|
"encoding/json"
|
|
"net/http"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
"github.com/gitpod-io/local-app/pkg/config"
|
|
"github.com/gitpod-io/local-app/pkg/constants"
|
|
"github.com/gitpod-io/local-app/pkg/selfupdate"
|
|
"github.com/opencontainers/go-digest"
|
|
)
|
|
|
|
func TestVersionUpdateCmd(t *testing.T) {
|
|
RunCommandTests(t, []CommandTest{
|
|
{
|
|
Name: "happy path",
|
|
Commandline: []string{"version", "update"},
|
|
PrepServer: func(mux *http.ServeMux) {
|
|
newBinary := []byte("#!/bin/bash\necho hello world")
|
|
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/manifest.json", func(w http.ResponseWriter, r *http.Request) {
|
|
mf, err := json.Marshal(selfupdate.Manifest{
|
|
Version: semver.MustParse("v9999.0"),
|
|
Binaries: []selfupdate.Binary{
|
|
{
|
|
Filename: "gitpod",
|
|
OS: runtime.GOOS,
|
|
Arch: runtime.GOARCH,
|
|
Digest: digest.FromBytes(newBinary),
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, _ = w.Write(mf)
|
|
})
|
|
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/gitpod", func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = w.Write(newBinary)
|
|
})
|
|
},
|
|
Config: AddActiveTestContext(&config.Config{}),
|
|
},
|
|
{
|
|
Name: "no update needed",
|
|
Commandline: []string{"version", "update"},
|
|
PrepServer: func(mux *http.ServeMux) {
|
|
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/manifest.json", func(w http.ResponseWriter, r *http.Request) {
|
|
mf, err := json.Marshal(selfupdate.Manifest{
|
|
Version: constants.Version,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, _ = w.Write(mf)
|
|
})
|
|
},
|
|
Config: AddActiveTestContext(&config.Config{}),
|
|
},
|
|
})
|
|
}
|