Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/version-update_test.go
2497 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"encoding/json"
9
"net/http"
10
"runtime"
11
"testing"
12
13
"github.com/Masterminds/semver/v3"
14
"github.com/gitpod-io/local-app/pkg/config"
15
"github.com/gitpod-io/local-app/pkg/constants"
16
"github.com/gitpod-io/local-app/pkg/selfupdate"
17
"github.com/opencontainers/go-digest"
18
)
19
20
func TestVersionUpdateCmd(t *testing.T) {
21
RunCommandTests(t, []CommandTest{
22
{
23
Name: "happy path",
24
Commandline: []string{"version", "update"},
25
PrepServer: func(mux *http.ServeMux) {
26
newBinary := []byte("#!/bin/bash\necho hello world")
27
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/manifest.json", func(w http.ResponseWriter, r *http.Request) {
28
mf, err := json.Marshal(selfupdate.Manifest{
29
Version: semver.MustParse("v9999.0"),
30
Binaries: []selfupdate.Binary{
31
{
32
Filename: "gitpod",
33
OS: runtime.GOOS,
34
Arch: runtime.GOARCH,
35
Digest: digest.FromBytes(newBinary),
36
},
37
},
38
})
39
if err != nil {
40
t.Fatal(err)
41
}
42
_, _ = w.Write(mf)
43
})
44
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/gitpod", func(w http.ResponseWriter, r *http.Request) {
45
_, _ = w.Write(newBinary)
46
})
47
},
48
Config: AddActiveTestContext(&config.Config{}),
49
},
50
{
51
Name: "no update needed",
52
Commandline: []string{"version", "update"},
53
PrepServer: func(mux *http.ServeMux) {
54
mux.HandleFunc(selfupdate.GitpodCLIBasePath+"/manifest.json", func(w http.ResponseWriter, r *http.Request) {
55
mf, err := json.Marshal(selfupdate.Manifest{
56
Version: constants.Version,
57
})
58
if err != nil {
59
t.Fatal(err)
60
}
61
_, _ = w.Write(mf)
62
})
63
},
64
Config: AddActiveTestContext(&config.Config{}),
65
},
66
})
67
}
68
69