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