Skip to content

Commit

Permalink
Merge branch 'tpip-check' of https://github.com/Open-CMSIS-Pack/cpackget
Browse files Browse the repository at this point in the history
 into tpip-check
  • Loading branch information
soumeh01 committed Sep 6, 2023
2 parents b37364d + 4d633cc commit 3b82288
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 24 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/ubuntu-22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:23.04

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get -y install \
build-essential \
curl \
less \
git \
golang \
gopls \
delve \
go-staticcheck

RUN go install honnef.co/go/tools/cmd/staticcheck@latest

CMD ["/bin/bash"]
13 changes: 13 additions & 0 deletions .devcontainer/ubuntu-22.04/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Ubuntu-23.04",
"build": { "dockerfile": "Dockerfile" },

"customizations": {
"vscode": {
"extensions": [
"golang.go",
"ms-azuretools.vscode-docker"
]
}
}
}
5 changes: 1 addition & 4 deletions cmd/commands/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ If the .checksum file is in another directory, specify it with the -p/--path fla
Args: cobra.ExactArgs(1),
PersistentPreRunE: configureInstallerGlobalCmd,
RunE: func(cmd *cobra.Command, args []string) error {
if checksumVerifyCmdFlags.checksumPath != "" {
return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath)
}
return cryptography.VerifyChecksum(args[0], "")
return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath)
},
}
10 changes: 1 addition & 9 deletions cmd/commands/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package commands

import (
"os"
"runtime"

"github.com/open-cmsis-pack/cpackget/cmd/installer"
log "github.com/sirupsen/logrus"
Expand All @@ -32,16 +31,9 @@ var IndexCmd = &cobra.Command{
},
}

// getLongIndexDescription prints a "Windows friendly" long description,
// using the correct path slashes
func getLongIndexDescription() string {
if runtime.GOOS == "windows" {
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `\.Web\index.pidx using the file specified by the given url.
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `/.Web/index.pidx using the file specified by the given url.
If there's already an index file, cpackget won't overwrite it. Use "-f" to do so.`
} else {
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `/.Web/index.pidx using the file specified by the given url.
If there's already an index file, cpackget won't overwrite it. Use "-f" to do so.`
}
}

func init() {
Expand Down
18 changes: 18 additions & 0 deletions cmd/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ var listCmdTests = []TestCase{
t.assert.Nil(localRepository.Write())
},
},
/* TODO
{
name: "test listing required packs",
args: []string{"list", "required"},
createPackRoot: true,
expectedStdout: []string{"TheVendor::[email protected]", "Vendor::[email protected]"},
setUpFunc: func(t *TestCase) {
packRoot := os.Getenv("CMSIS_PACK_ROOT")
packFolder := filepath.Join(packRoot, "Vendor", "Pack", "1.2.3")
t.assert.Nil(os.MkdirAll(packFolder, 0700))
t.assert.Nil(os.WriteFile(filepath.Join(packFolder, "Vendor.Pack.pdsc"), []byte(""), 0600))
localRepository := installer.Installation.LocalPidx
t.assert.Nil(localRepository.Read())
t.assert.Nil(localRepository.AddPdsc(xml.PdscTag{Vendor: "Vendor", Name: "PackInstalledViaPdsc", Version: "1.2.3"}))
t.assert.Nil(localRepository.Write())
},
},
*/
}

func TestListCmd(t *testing.T) {
Expand Down
10 changes: 1 addition & 9 deletions cmd/commands/update_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package commands

import (
"os"
"runtime"

"github.com/open-cmsis-pack/cpackget/cmd/installer"
"github.com/open-cmsis-pack/cpackget/cmd/utils"
Expand Down Expand Up @@ -43,16 +42,9 @@ var UpdateIndexCmd = &cobra.Command{
},
}

// getLongUpdateDescription prints a "Windows friendly" long description,
// using the correct path slashes
func getLongUpdateDescription() string {
if runtime.GOOS == "windows" {
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `\.Web\index.pidx using the URL in <url> tag inside index.pidx.
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `/.Web/index.pidx using the URL in <url> tag inside index.pidx.
By default it will also check if all PDSC files under .Web/ need update as well. This can be disabled via the "--sparse" flag.`
} else {
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + `/.Web/index.pidx using the URL in <url> tag inside index.pidx.
By default it will also check if all PDSC files under .Web/ need update as well. This can be disabled via the "--sparse" flag.`
}
}

func init() {
Expand Down
20 changes: 19 additions & 1 deletion cmd/installer/root_pack_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ func TestAddPack(t *testing.T) {
checkPackIsInstalled(t, packInfoToType(packToReinstall))
})

t.Run("test force-reinstalling an installed pack using encoded progress", func(t *testing.T) {
localTestingDir := "test-add-pack-force-reinstall-already-installed-using-encoded-progress"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
defer removePackRoot(localTestingDir)
utils.SetEncodedProgress(true)

packPath := packToReinstall
addPack(t, packPath, ConfigType{})

err := installer.AddPack(packPath, !CheckEula, !ExtractEula, ForceReinstall, !NoRequirements, Timeout)
assert.Nil(err)

packToReinstall, err := utils.ExtractPackInfo(packPath)
assert.Nil(err)
checkPackIsInstalled(t, packInfoToType(packToReinstall))
})

t.Run("test force-reinstalling a pack with a user interruption", func(t *testing.T) {
localTestingDir := "test-add-pack-force-reinstall-user-interruption"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
Expand Down Expand Up @@ -1471,7 +1489,7 @@ func TestAddPack(t *testing.T) {
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
installer.Installation.WebDir = filepath.Join(testDir, "public_index")
//defer removePackRoot(localTestingDir)
defer removePackRoot(localTestingDir)

addPack(t, publicRemotePack123alpha, ConfigType{IsPublic: true})

Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/root_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func generatePaths(t *testing.T) map[string]string {
return map[string]string{
"regular absolute path": absPath,
"absolute path with ..": filepath.Join(absPath, "..", dirName),
"absolute path with :/": strings.Replace(absPath, ":\\", "/", 1),
"absolute path with :/": strings.Replace(absPath, ":\\", "/", 1), // creates issues on Windows-FS, defer delete not working
"all forward slashes": strings.ReplaceAll(absPath, "\\", "/"),
"multiple leading slashes": strings.Replace(absPath, ":\\", ":\\\\\\\\", 1),
"multiple trailing slashes": absPath + "\\\\\\\\",
Expand Down
10 changes: 10 additions & 0 deletions cmd/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ func TestUnsetReadOnlyR(t *testing.T) {
assert.Equal(t, fs.FileMode(0777), permBits&0777)
}

func TestTinyFunctions(t *testing.T) {
assert := assert.New(t)

utils.SetEncodedProgress(true)
assert.True(utils.GetEncodedProgress())

utils.SetSkipTouch(true)
assert.True(utils.GetSkipTouch())
}

func init() {
logLevel := log.InfoLevel
if os.Getenv("LOG_LEVEL") == "debug" {
Expand Down

0 comments on commit 3b82288

Please sign in to comment.