-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into go_version_update
- Loading branch information
Showing
9 changed files
with
195 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
/* Copyright Contributors to the cpackget project. */ | ||
|
||
package commands | ||
|
||
import ( | ||
"github.com/open-cmsis-pack/cpackget/cmd/installer" | ||
"github.com/open-cmsis-pack/cpackget/cmd/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var connectionCmdFlags struct { | ||
// downloadPdscFiles forces all pdsc files from the public index to be downloaded | ||
downloadPdscFiles bool | ||
|
||
// Reports encoded progress for files and download when used by other tools | ||
encodedProgress bool | ||
|
||
// skipTouch does not touch pack.idx after adding | ||
skipTouch bool | ||
|
||
// check connection status | ||
checkConnection bool | ||
} | ||
|
||
var ConnectionCmd = &cobra.Command{ | ||
Use: "connection [<url>]", | ||
Short: "Check online connection to default or given URL", | ||
Long: `Checks if the given or default url is accessible | ||
The url is optional. Ex "cpackget connection https://www.keil.com/pack"`, | ||
Args: cobra.MinimumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
utils.SetEncodedProgress(connectionCmdFlags.encodedProgress) | ||
utils.SetSkipTouch(connectionCmdFlags.skipTouch) | ||
|
||
var indexPath string | ||
if len(args) > 0 { | ||
indexPath = args[0] | ||
} | ||
createPackRoot = false | ||
var err error | ||
|
||
if indexPath == "" { // try to fetch from environment | ||
err = configureInstaller(cmd, args) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
indexPath, err = installer.GetIndexPath(indexPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = utils.CheckConnection(indexPath, viper.GetInt("timeout")) | ||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
ConnectionCmd.Flags().BoolVarP(&connectionCmdFlags.encodedProgress, "encoded-progress", "E", false, "Reports encoded progress for files and download when used by other tools") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
/* Copyright Contributors to the cpackget project. */ | ||
|
||
package commands_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
var ( | ||
urlPath string = "https://www.keil.com" | ||
wrongURLPath string = "https://www.keilll.com" | ||
) | ||
|
||
var connectionCmdTests = []TestCase{ | ||
{ | ||
name: "test help command", | ||
args: []string{"help", "connection"}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "test checking connection", | ||
args: []string{"connection", urlPath}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "test checking invalid url", | ||
args: []string{"connection", wrongURLPath}, | ||
expectedErr: errors.New("remote server is offline or cannot be reached"), | ||
}, | ||
|
||
{ // set up environment for next test | ||
name: "test checking default connection", | ||
args: []string{"init"}, | ||
noCleanup: true, | ||
setUpFunc: func(t *TestCase) { | ||
server := NewServer() | ||
t.args = append(t.args, server.URL()+"index.pidx") | ||
server.AddRoute("index.pidx", []byte(`<?xml version="1.0" encoding="UTF-8" ?> | ||
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="https://www.w3.org/2001/XMLSchema-instance"> | ||
<vendor>TheVendor</vendor> | ||
<url>https://www.keil.com/</url> | ||
<timestamp>2021-10-17T12:21:59.1747971+00:00</timestamp> | ||
<pindex> | ||
<pdsc url="https://www.keil.com" vendor="Keil" name="PackName" version="1.2.3" /> | ||
</pindex> | ||
</index>`)) | ||
}, | ||
}, | ||
{ | ||
name: "test checking default connection", | ||
args: []string{"connection"}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
func TestConnectionCmd(t *testing.T) { | ||
runTests(t, connectionCmdTests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters