From 874d2e2e01da4cfa7bab3446913d9112d12cf9b5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 12 Jul 2022 12:40:51 +0200 Subject: [PATCH 01/33] testsuite: Added helper functions to handle test envs --- testsuite/env.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 testsuite/env.go diff --git a/testsuite/env.go b/testsuite/env.go new file mode 100644 index 00000000000..0a7c3b4d2d5 --- /dev/null +++ b/testsuite/env.go @@ -0,0 +1,59 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package integrationtest + +import ( + "testing" + + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +// Environment is a test environment for the test suite. +type Environment struct { + rootDir *paths.Path + downloadsDir *paths.Path + t *require.Assertions +} + +// SharedDownloadDir returns the shared downloads directory. +func SharedDownloadDir(t *testing.T) *paths.Path { + downloadsDir := paths.TempDir().Join("arduino-cli-test-suite-staging") + require.NoError(t, downloadsDir.MkdirAll()) + return downloadsDir +} + +// NewEnvironment creates a new test environment. +func NewEnvironment(t *testing.T) *Environment { + downloadsDir := SharedDownloadDir(t) + rootDir, err := paths.MkTempDir("", "arduino-cli-test-suite") + require.NoError(t, err) + return &Environment{ + rootDir: rootDir, + downloadsDir: downloadsDir, + t: require.New(t), + } +} + +// CleanUp removes the test environment. +func (e *Environment) CleanUp() { + e.t.NoError(e.rootDir.RemoveAll()) +} + +// Root returns the root dir of the environment. +func (e *Environment) Root() *paths.Path { + return e.rootDir +} From dae32426366a8bdbee61f85d7dcdba10440230ad Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 12 Jul 2022 12:42:01 +0200 Subject: [PATCH 02/33] testsuite: Added helper functions to run arduino-cli --- testsuite/arduino-cli.go | 107 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 testsuite/arduino-cli.go diff --git a/testsuite/arduino-cli.go b/testsuite/arduino-cli.go new file mode 100644 index 00000000000..78942d54f48 --- /dev/null +++ b/testsuite/arduino-cli.go @@ -0,0 +1,107 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package integrationtest + +import ( + "bytes" + "context" + "fmt" + "io" + "testing" + + "github.com/arduino/arduino-cli/executils" + "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" +) + +// ArduinoCLI is an Arduino CLI client. +type ArduinoCLI struct { + path *paths.Path + t *require.Assertions + proc *executils.Process + cliConfigPath *paths.Path + daemonAddr string + daemonConn *grpc.ClientConn + daemonClient commands.ArduinoCoreServiceClient +} + +// NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. +func NewArduinoCliWithinEnvironment(t *testing.T, cliPath *paths.Path, env *Environment) *ArduinoCLI { + cli := NewArduinoCli(t, cliPath) + cli.cliConfigPath = env.Root().Join("arduino-cli.yaml") + config := fmt.Sprintf(` +directories: + data: %s + downloads: %s + user: %s +`, + env.Root().Join("arduino15"), + env.Root().Join("arduino15/staging"), + env.Root().Join("Arduino")) + require.NoError(t, cli.cliConfigPath.WriteFile([]byte(config))) + return cli +} + +// NewArduinoCli creates a new Arduino CLI client. +func NewArduinoCli(t *testing.T, cliPath *paths.Path) *ArduinoCLI { + return &ArduinoCLI{ + path: cliPath, + t: require.New(t), + } +} + +// CleanUp closes the Arduino CLI client. +func (cli *ArduinoCLI) CleanUp() { + if cli.proc != nil { + cli.proc.Kill() + cli.proc.Wait() + } +} + +// Run executes the given arduino-cli command and returns the output. +func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { + if cli.cliConfigPath != nil { + args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) + } + cliProc, err := executils.NewProcessFromPath(nil, cli.path, args...) + cli.t.NoError(err) + stdout, err := cliProc.StdoutPipe() + cli.t.NoError(err) + stderr, err := cliProc.StderrPipe() + cli.t.NoError(err) + _, err = cliProc.StdinPipe() + cli.t.NoError(err) + + cli.t.NoError(cliProc.Start()) + + var stdoutBuf, stderrBuf bytes.Buffer + stdoutCtx, stdoutCancel := context.WithCancel(context.Background()) + stderrCtx, stderrCancel := context.WithCancel(context.Background()) + go func() { + io.Copy(&stdoutBuf, stdout) + stdoutCancel() + }() + go func() { + io.Copy(&stderrBuf, stderr) + stderrCancel() + }() + cliErr := cliProc.Wait() + <-stdoutCtx.Done() + <-stderrCtx.Done() + return stdoutBuf.Bytes(), stderrBuf.Bytes(), cliErr +} From 9679f1ca0311749305b9c0e57acc61f965bc9be8 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 12 Jul 2022 13:21:57 +0200 Subject: [PATCH 03/33] testsuite: Added colored output to arduino-cli Run helper --- testsuite/arduino-cli.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/testsuite/arduino-cli.go b/testsuite/arduino-cli.go index 78942d54f48..f9d94d0c1eb 100644 --- a/testsuite/arduino-cli.go +++ b/testsuite/arduino-cli.go @@ -20,11 +20,13 @@ import ( "context" "fmt" "io" + "strings" "testing" "github.com/arduino/arduino-cli/executils" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" + "github.com/fatih/color" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) @@ -75,6 +77,7 @@ func (cli *ArduinoCLI) CleanUp() { // Run executes the given arduino-cli command and returns the output. func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { + fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " "))) if cli.cliConfigPath != nil { args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) } @@ -93,15 +96,17 @@ func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { stdoutCtx, stdoutCancel := context.WithCancel(context.Background()) stderrCtx, stderrCancel := context.WithCancel(context.Background()) go func() { - io.Copy(&stdoutBuf, stdout) + io.Copy(&stdoutBuf, io.TeeReader(stdout, os.Stdout)) stdoutCancel() }() go func() { - io.Copy(&stderrBuf, stderr) + io.Copy(&stderrBuf, io.TeeReader(stderr, os.Stderr)) stderrCancel() }() cliErr := cliProc.Wait() <-stdoutCtx.Done() <-stderrCtx.Done() + fmt.Println(color.HiBlackString("<<< Run completed (err = %v)", cliErr)) + return stdoutBuf.Bytes(), stderrBuf.Bytes(), cliErr } From 46c381ee3d84d1153c0b2ad57686d3add74a592c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 12 Jul 2022 14:13:10 +0200 Subject: [PATCH 04/33] testsuite: Pass cli config through env variables --- testsuite/arduino-cli.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/testsuite/arduino-cli.go b/testsuite/arduino-cli.go index f9d94d0c1eb..c8609ee277b 100644 --- a/testsuite/arduino-cli.go +++ b/testsuite/arduino-cli.go @@ -36,6 +36,7 @@ type ArduinoCLI struct { path *paths.Path t *require.Assertions proc *executils.Process + cliEnvVars []string cliConfigPath *paths.Path daemonAddr string daemonConn *grpc.ClientConn @@ -45,17 +46,11 @@ type ArduinoCLI struct { // NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. func NewArduinoCliWithinEnvironment(t *testing.T, cliPath *paths.Path, env *Environment) *ArduinoCLI { cli := NewArduinoCli(t, cliPath) - cli.cliConfigPath = env.Root().Join("arduino-cli.yaml") - config := fmt.Sprintf(` -directories: - data: %s - downloads: %s - user: %s -`, - env.Root().Join("arduino15"), - env.Root().Join("arduino15/staging"), - env.Root().Join("Arduino")) - require.NoError(t, cli.cliConfigPath.WriteFile([]byte(config))) + cli.cliEnvVars = []string{ + fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.Root().Join("arduino15")), + fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", env.Root().Join("arduino15/staging")), + fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.Root().Join("Arduino")), + } return cli } @@ -77,11 +72,11 @@ func (cli *ArduinoCLI) CleanUp() { // Run executes the given arduino-cli command and returns the output. func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { - fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " "))) if cli.cliConfigPath != nil { args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) } - cliProc, err := executils.NewProcessFromPath(nil, cli.path, args...) + fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " "))) + cliProc, err := executils.NewProcessFromPath(cli.cliEnvVars, cli.path, args...) cli.t.NoError(err) stdout, err := cliProc.StdoutPipe() cli.t.NoError(err) From 9ae6760080000660bfcd5614cbf9722db86b4e25 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Jul 2022 16:22:05 +0200 Subject: [PATCH 05/33] testsuite: added env commands to download and extract files --- testsuite/env.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/testsuite/env.go b/testsuite/env.go index 0a7c3b4d2d5..55675805e3f 100644 --- a/testsuite/env.go +++ b/testsuite/env.go @@ -16,9 +16,17 @@ package integrationtest import ( + "context" + "crypto/md5" + "encoding/hex" + "io" + "net/http" + "net/url" + "path/filepath" "testing" "github.com/arduino/go-paths-helper" + "github.com/codeclysm/extract/v3" "github.com/stretchr/testify/require" ) @@ -57,3 +65,65 @@ func (e *Environment) CleanUp() { func (e *Environment) Root() *paths.Path { return e.rootDir } + +// Download downloads a file from a URL and returns the path to the downloaded file. +// The file is saved and cached in a shared downloads directory. If the file already exists, it is not downloaded again. +func (e *Environment) Download(rawURL string) *paths.Path { + url, err := url.Parse(rawURL) + e.t.NoError(err) + + filename := filepath.Base(url.Path) + if filename == "/" { + filename = "" + } else { + filename = "-" + filename + } + + hash := md5.Sum([]byte(rawURL)) + resource := e.downloadsDir.Join(hex.EncodeToString(hash[:]) + filename) + + // If the resource already exist, return it + if resource.Exist() { + return resource + } + + // Download file + resp, err := http.Get(rawURL) + e.t.NoError(err) + defer resp.Body.Close() + + // Copy data in a temp file + tmp := resource.Parent().Join(resource.Base() + ".tmp") + out, err := tmp.Create() + e.t.NoError(err) + defer tmp.Remove() + defer out.Close() + + // Write the body to file + _, err = io.Copy(out, resp.Body) + e.t.NoError(err) + e.t.NoError(out.Close()) + + // Rename the file to its final destination + e.t.NoError(tmp.Rename(resource)) + + return resource +} + +// Extract extracts a tarball to a directory named as the archive +// with the "_content" suffix added. Returns the path to the directory. +func (e *Environment) Extract(archive *paths.Path) *paths.Path { + destDir := archive.Parent().Join(archive.Base() + "_content") + if destDir.Exist() { + return destDir + } + + file, err := archive.Open() + e.t.NoError(err) + defer file.Close() + + err = extract.Archive(context.Background(), file, destDir.String(), nil) + e.t.NoError(err) + + return destDir +} From 1465a20caca81110bc78932a03984b65386ad334 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Jul 2022 16:22:48 +0200 Subject: [PATCH 06/33] testsuite: added commands to start cli daemon and run some gRPC calls --- testsuite/arduino-cli.go | 131 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/testsuite/arduino-cli.go b/testsuite/arduino-cli.go index c8609ee277b..5aedb4cbf97 100644 --- a/testsuite/arduino-cli.go +++ b/testsuite/arduino-cli.go @@ -20,8 +20,11 @@ import ( "context" "fmt" "io" + "os" "strings" + "sync" "testing" + "time" "github.com/arduino/arduino-cli/executils" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -105,3 +108,131 @@ func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { return stdoutBuf.Bytes(), stderrBuf.Bytes(), cliErr } + +// StartDeamon starts the Arduino CLI daemon. It returns the address of the daemon. +func (cli *ArduinoCLI) StartDeamon(verbose bool) string { + args := []string{"daemon", "--format", "json"} + if cli.cliConfigPath != nil { + args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) + } + if verbose { + args = append(args, "-v", "--log-level", "debug") + } + cliProc, err := executils.NewProcessFromPath(cli.cliEnvVars, cli.path, args...) + cli.t.NoError(err) + stdout, err := cliProc.StdoutPipe() + cli.t.NoError(err) + stderr, err := cliProc.StderrPipe() + cli.t.NoError(err) + _, err = cliProc.StdinPipe() + cli.t.NoError(err) + + cli.t.NoError(cliProc.Start()) + cli.proc = cliProc + + // var daemonAddr struct { + // IP string + // Port string + // } + // dec := json.NewDecoder(stdout) + // cli.t.NoError(dec.Decode(&daemonAddr)) + // cli.daemonAddr = daemonAddr.IP + ":" + daemonAddr.Port + cli.daemonAddr = "127.0.0.1:50051" + + copy := func(dst io.Writer, src io.Reader) { + buff := make([]byte, 1024) + for { + n, err := src.Read(buff) + if err != nil { + return + } + dst.Write([]byte(color.YellowString(string(buff[:n])))) + } + } + go copy(os.Stdout, stdout) + go copy(os.Stderr, stderr) + conn, err := grpc.Dial(cli.daemonAddr, grpc.WithInsecure(), grpc.WithBlock()) + cli.t.NoError(err) + cli.daemonConn = conn + cli.daemonClient = commands.NewArduinoCoreServiceClient(conn) + + return cli.daemonAddr +} + +// ArduinoCLIInstance is an Arduino CLI gRPC instance. +type ArduinoCLIInstance struct { + cli *ArduinoCLI + instance *commands.Instance +} + +var logCallfMutex sync.Mutex + +func logCallf(format string, a ...interface{}) { + logCallfMutex.Lock() + fmt.Print(color.HiRedString(format, a...)) + logCallfMutex.Unlock() +} + +// Create calls the "Create" gRPC method. +func (cli *ArduinoCLI) Create() *ArduinoCLIInstance { + logCallf(">>> Create()") + resp, err := cli.daemonClient.Create(context.Background(), &commands.CreateRequest{}) + cli.t.NoError(err) + logCallf(" -> %v\n", resp) + return &ArduinoCLIInstance{ + cli: cli, + instance: resp.Instance, + } +} + +// Init calls the "Init" gRPC method. +func (inst *ArduinoCLIInstance) Init(profile string, sketchPath string, respCB func(*commands.InitResponse)) error { + initReq := &commands.InitRequest{ + Instance: inst.instance, + Profile: profile, + SketchPath: sketchPath, + } + logCallf(">>> Init(%v)\n", initReq) + initClient, err := inst.cli.daemonClient.Init(context.Background(), initReq) + if err != nil { + return err + } + for { + msg, err := initClient.Recv() + if err == io.EOF { + logCallf("<<< Init EOF\n") + return nil + } + if err != nil { + return err + } + if respCB != nil { + respCB(msg) + } + } +} + +// BoardList calls the "BoardList" gRPC method. +func (inst *ArduinoCLIInstance) BoardList(timeout time.Duration) (*commands.BoardListResponse, error) { + boardListReq := &commands.BoardListRequest{ + Instance: inst.instance, + Timeout: timeout.Milliseconds(), + } + logCallf(">>> BoardList(%v) -> ", boardListReq) + resp, err := inst.cli.daemonClient.BoardList(context.Background(), boardListReq) + logCallf("err=%v\n", err) + return resp, err +} + +// BoardListWatch calls the "BoardListWatch" gRPC method. +func (inst *ArduinoCLIInstance) BoardListWatch() (commands.ArduinoCoreService_BoardListWatchClient, error) { + boardListWatchReq := &commands.BoardListWatchRequest{ + Instance: inst.instance, + } + logCallf(">>> BoardListWatch(%v)\n", boardListWatchReq) + watcher, err := inst.cli.daemonClient.BoardListWatch(context.Background()) + if err != nil { + return watcher, err + } + return watcher, watcher.Send(boardListWatchReq) +} From f53c67307e4342063af8ec9e4836ba5715e3741f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Jul 2022 16:25:00 +0200 Subject: [PATCH 07/33] testsuite: moved test harness inside 'internal' package --- {testsuite => internal/integrationtest}/arduino-cli.go | 0 {testsuite => internal/integrationtest}/env.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {testsuite => internal/integrationtest}/arduino-cli.go (100%) rename {testsuite => internal/integrationtest}/env.go (100%) diff --git a/testsuite/arduino-cli.go b/internal/integrationtest/arduino-cli.go similarity index 100% rename from testsuite/arduino-cli.go rename to internal/integrationtest/arduino-cli.go diff --git a/testsuite/env.go b/internal/integrationtest/env.go similarity index 100% rename from testsuite/env.go rename to internal/integrationtest/env.go From 82e98ee2e88f42ccba8a1a96fb1ca68c49d64cc1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Jul 2022 16:30:59 +0200 Subject: [PATCH 08/33] testsuite: added first daemon test for gRPC board watch --- .github/workflows/test-go-task.yml | 3 + .../arduino-cli_daemon_test.go | 87 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 internal/integrationtest/arduino-cli_daemon_test.go diff --git a/.github/workflows/test-go-task.yml b/.github/workflows/test-go-task.yml index 90df72399eb..decd3ff2c89 100644 --- a/.github/workflows/test-go-task.yml +++ b/.github/workflows/test-go-task.yml @@ -89,6 +89,9 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x + - name: Build arduino-cli + run: task go:build + - name: Run tests run: task go:test diff --git a/internal/integrationtest/arduino-cli_daemon_test.go b/internal/integrationtest/arduino-cli_daemon_test.go new file mode 100644 index 00000000000..8f311ca9752 --- /dev/null +++ b/internal/integrationtest/arduino-cli_daemon_test.go @@ -0,0 +1,87 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package integrationtest + +import ( + "context" + "fmt" + "io" + "testing" + "time" + + "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +func TestArduinoCliDaemon(t *testing.T) { + env := NewEnvironment(t) + defer env.CleanUp() + + cli := NewArduinoCliWithinEnvironment(t, paths.New("..", "..", "arduino-cli"), env) + defer cli.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + + _ = cli.StartDeamon(false) + + inst := cli.Create() + require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + fmt.Printf("INIT> %v\n", ir.GetMessage()) + })) + + // Run a one-shot board list + boardListResp, err := inst.BoardList(time.Second) + require.NoError(t, err) + fmt.Printf("Got boardlist response with %d ports\n", len(boardListResp.GetPorts())) + + // Run a one-shot board list again (should not fail) + boardListResp, err = inst.BoardList(time.Second) + require.NoError(t, err) + fmt.Printf("Got boardlist response with %d ports\n", len(boardListResp.GetPorts())) + + testWatcher := func() { + // Run watcher + watcher, err := inst.BoardListWatch() + require.NoError(t, err) + ctx, cancel := context.WithCancel(context.Background()) + go func() { + defer cancel() + for { + msg, err := watcher.Recv() + if err == io.EOF { + fmt.Println("Watcher EOF") + return + } + require.Empty(t, msg.Error, "Board list watcher returned an error") + require.NoError(t, err, "BoardListWatch grpc call returned an error") + fmt.Printf("WATCH> %v\n", msg) + } + }() + time.Sleep(time.Second) + require.NoError(t, watcher.CloseSend()) + select { + case <-ctx.Done(): + // all right! + case <-time.After(time.Second): + require.Fail(t, "BoardListWatch didn't close") + } + } + + testWatcher() + testWatcher() +} From b453bca24d2631c4aa36f6cd7f1477eec3499ee2 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 28 Jul 2022 12:16:51 +0200 Subject: [PATCH 09/33] testsuite: added http server helper --- internal/integrationtest/http.go | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 internal/integrationtest/http.go diff --git a/internal/integrationtest/http.go b/internal/integrationtest/http.go new file mode 100644 index 00000000000..d81590186bb --- /dev/null +++ b/internal/integrationtest/http.go @@ -0,0 +1,49 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package integrationtest + +import ( + "fmt" + "net/http" + "net/url" + "testing" + + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +// HTTPServeFile spawn an http server that serve a single file. The server +// is started on the given port. The URL to the file and a cleanup function are returned. +func HTTPServeFile(t *testing.T, port uint16, path *paths.Path) (*url.URL, func()) { + mux := http.NewServeMux() + mux.HandleFunc("/"+path.Base(), func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, path.String()) + }) + server := &http.Server{ + Addr: fmt.Sprintf(":%d", port), + Handler: mux, + } + + fileURL, err := url.Parse(fmt.Sprintf("http://127.0.0.1:%d/%s", port, path.Base())) + require.NoError(t, err) + + go func() { + err := server.ListenAndServe() + require.Equal(t, err, http.ErrServerClosed) + }() + + return fileURL, func() { server.Close() } +} From db39fb0ac524dea5f4d1a1a37acc1b226466b8ee Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Jul 2022 10:44:33 +0200 Subject: [PATCH 10/33] testsuite: added JSON helpers --- arduino/discovery/discovery_client/go.mod | 5 +-- arduino/discovery/discovery_client/go.sum | 19 ++++++++--- client_example/go.mod | 2 +- client_example/go.sum | 14 ++++++-- docsgen/go.mod | 7 ++-- docsgen/go.sum | 21 +++++++++--- go.mod | 17 +++++++--- go.sum | 26 ++++++++++++--- internal/integrationtest/json.go | 40 +++++++++++++++++++++++ 9 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 internal/integrationtest/json.go diff --git a/arduino/discovery/discovery_client/go.mod b/arduino/discovery/discovery_client/go.mod index 840449b3c36..5fcd8c8e4da 100644 --- a/arduino/discovery/discovery_client/go.mod +++ b/arduino/discovery/discovery_client/go.mod @@ -15,13 +15,14 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect github.com/leonelquinteros/gotext v1.4.0 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/rivo/uniseg v0.2.0 // indirect github.com/sirupsen/logrus v1.4.2 // indirect golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.6 // indirect google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect google.golang.org/grpc v1.38.0 // indirect diff --git a/arduino/discovery/discovery_client/go.sum b/arduino/discovery/discovery_client/go.sum index 5de1d6d0afb..9c93f57bba3 100644 --- a/arduino/discovery/discovery_client/go.sum +++ b/arduino/discovery/discovery_client/go.sum @@ -192,6 +192,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/itchyny/gojq v0.12.8/go.mod h1:gE2kZ9fVRU0+JAksaTzjIlgnCa2akU+a1V0WXgJQN5c= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -228,9 +230,10 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -264,6 +267,8 @@ github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583/go.mod h1:sFPiU/U github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -295,6 +300,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -472,8 +480,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -669,8 +679,9 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/client_example/go.mod b/client_example/go.mod index d49c01cc039..b00743c6f6f 100644 --- a/client_example/go.mod +++ b/client_example/go.mod @@ -12,7 +12,7 @@ require ( require ( github.com/golang/protobuf v1.5.2 // indirect golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.6 // indirect google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect google.golang.org/protobuf v1.26.0 // indirect diff --git a/client_example/go.sum b/client_example/go.sum index 5f94f6a6de6..4ea6136f5f0 100644 --- a/client_example/go.sum +++ b/client_example/go.sum @@ -187,6 +187,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/itchyny/gojq v0.12.8/go.mod h1:gE2kZ9fVRU0+JAksaTzjIlgnCa2akU+a1V0WXgJQN5c= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -221,7 +223,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -249,6 +252,7 @@ github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583/go.mod h1:sFPiU/U github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -278,6 +282,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -455,8 +462,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -653,6 +662,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/docsgen/go.mod b/docsgen/go.mod index f7ae2aaf1a2..b2fb83c6364 100644 --- a/docsgen/go.mod +++ b/docsgen/go.mod @@ -43,8 +43,8 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/marcinbor85/gohex v0.0.0-20210308104911-55fb1c624d84 // indirect github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect github.com/miekg/dns v1.1.43 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect @@ -53,6 +53,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583 // indirect github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect + github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/schollz/closestmatch v2.1.0+incompatible // indirect github.com/sergi/go-diff v1.1.0 // indirect @@ -73,7 +74,7 @@ require ( go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 // indirect golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.6 // indirect google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect google.golang.org/grpc v1.38.0 // indirect diff --git a/docsgen/go.sum b/docsgen/go.sum index 4ecc5bb0182..bd15643e3a5 100644 --- a/docsgen/go.sum +++ b/docsgen/go.sum @@ -214,6 +214,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/itchyny/gojq v0.12.8/go.mod h1:gE2kZ9fVRU0+JAksaTzjIlgnCa2akU+a1V0WXgJQN5c= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -261,10 +263,11 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= @@ -302,6 +305,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -347,6 +352,9 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -532,8 +540,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -737,8 +747,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/go.mod b/go.mod index e335d26045b..121b55f4275 100644 --- a/go.mod +++ b/go.mod @@ -27,8 +27,8 @@ require ( github.com/mailru/easyjson v0.7.7 github.com/marcinbor85/gohex v0.0.0-20210308104911-55fb1c624d84 github.com/mattn/go-colorable v0.1.8 - github.com/mattn/go-isatty v0.0.12 - github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-isatty v0.0.14 + github.com/mattn/go-runewidth v0.0.13 // indirect github.com/miekg/dns v1.1.43 // indirect github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect github.com/pkg/errors v0.9.1 @@ -57,6 +57,11 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) +require ( + github.com/itchyny/gojq v0.12.8 + github.com/tidwall/gjson v1.14.1 +) + require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/creack/goselect v0.1.2 // indirect @@ -66,6 +71,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/itchyny/timefmt-go v0.1.3 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect @@ -76,6 +82,7 @@ require ( github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/pelletier/go-toml v1.9.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/spf13/afero v1.6.0 // indirect @@ -83,10 +90,12 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/src-d/gcfg v1.4.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect github.com/xanzy/ssh-agent v0.2.1 // indirect - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index af28bd4122c..19232321d69 100644 --- a/go.sum +++ b/go.sum @@ -216,6 +216,10 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/itchyny/gojq v0.12.8 h1:Zxcwq8w4IeR8JJYEtoG2MWJZUv0RGY6QqJcO1cqV8+A= +github.com/itchyny/gojq v0.12.8/go.mod h1:gE2kZ9fVRU0+JAksaTzjIlgnCa2akU+a1V0WXgJQN5c= +github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -261,10 +265,11 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= @@ -302,6 +307,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -347,6 +354,12 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -532,8 +545,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -737,8 +752,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/integrationtest/json.go b/internal/integrationtest/json.go new file mode 100644 index 00000000000..d11c2db1cd1 --- /dev/null +++ b/internal/integrationtest/json.go @@ -0,0 +1,40 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package integrationtest + +import ( + "encoding/json" + "testing" + + "github.com/itchyny/gojq" + "github.com/stretchr/testify/require" +) + +// JQQuery performs a test on a given json output. A jq-like query is performed +// on the given jsonData and the result is compared with the expected output. +// If the output doesn't match the test fails. If msgAndArgs are provided they +// will be used to explain the error. +func JQQuery(t *testing.T, jsonData []byte, jqQuery string, expected interface{}, msgAndArgs ...interface{}) { + var data interface{} + require.NoError(t, json.Unmarshal(jsonData, &data)) + q, err := gojq.Parse(jqQuery) + require.NoError(t, err) + i := q.Run(data) + v, ok := i.Next() + require.True(t, ok) + require.IsType(t, expected, v) + require.Equal(t, expected, v, msgAndArgs...) +} From f2c886e396b54ea38448202bbed820eb532e57b5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Jul 2022 10:46:17 +0200 Subject: [PATCH 11/33] testsuite: Added possibility to use shared download staging folder --- internal/integrationtest/arduino-cli.go | 20 ++++++++++++++----- .../arduino-cli_daemon_test.go | 5 ++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 5aedb4cbf97..30fd5729328 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -46,21 +46,31 @@ type ArduinoCLI struct { daemonClient commands.ArduinoCoreServiceClient } +// ArduinoCLIConfig is the configuration of the ArduinoCLI client +type ArduinoCLIConfig struct { + ArduinoCLIPath *paths.Path + UseSharedStagingFolder bool +} + // NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. -func NewArduinoCliWithinEnvironment(t *testing.T, cliPath *paths.Path, env *Environment) *ArduinoCLI { - cli := NewArduinoCli(t, cliPath) +func NewArduinoCliWithinEnvironment(t *testing.T, config *ArduinoCLIConfig, env *Environment) *ArduinoCLI { + cli := NewArduinoCli(t, config) + staging := env.downloadsDir + if !config.UseSharedStagingFolder { + staging = env.Root().Join("arduino15/staging") + } cli.cliEnvVars = []string{ fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.Root().Join("arduino15")), - fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", env.Root().Join("arduino15/staging")), + fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", staging), fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.Root().Join("Arduino")), } return cli } // NewArduinoCli creates a new Arduino CLI client. -func NewArduinoCli(t *testing.T, cliPath *paths.Path) *ArduinoCLI { +func NewArduinoCli(t *testing.T, config *ArduinoCLIConfig) *ArduinoCLI { return &ArduinoCLI{ - path: cliPath, + path: config.ArduinoCLIPath, t: require.New(t), } } diff --git a/internal/integrationtest/arduino-cli_daemon_test.go b/internal/integrationtest/arduino-cli_daemon_test.go index 8f311ca9752..8b0f609b0eb 100644 --- a/internal/integrationtest/arduino-cli_daemon_test.go +++ b/internal/integrationtest/arduino-cli_daemon_test.go @@ -31,7 +31,10 @@ func TestArduinoCliDaemon(t *testing.T) { env := NewEnvironment(t) defer env.CleanUp() - cli := NewArduinoCliWithinEnvironment(t, paths.New("..", "..", "arduino-cli"), env) + cli := NewArduinoCliWithinEnvironment(t, &ArduinoCLIConfig{ + ArduinoCLIPath: paths.New("..", "..", "arduino-cli"), + UseSharedStagingFolder: true, + }, env) defer cli.CleanUp() _, _, err := cli.Run("core", "update-index") From 1ab2ef453e3f52efff47c06672a85ef97d5ee7b5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Jul 2022 10:50:31 +0200 Subject: [PATCH 12/33] testsuite: Converted a core_test.py test (WIP) --- internal/integrationtest/core/core_test.go | 158 +++++++++++++ .../integrationtest/testdata/test_index.json | 210 ++++++++++++++++++ 2 files changed, 368 insertions(+) create mode 100644 internal/integrationtest/core/core_test.go create mode 100644 internal/integrationtest/testdata/test_index.json diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go new file mode 100644 index 00000000000..76730cacbb2 --- /dev/null +++ b/internal/integrationtest/core/core_test.go @@ -0,0 +1,158 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package core_test + +import ( + "encoding/json" + "fmt" + "strings" + "testing" + + "github.com/arduino/arduino-cli/internal/integrationtest" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" +) + +func TestCoreSearch(t *testing.T) { + env := integrationtest.NewEnvironment(t) + defer env.CleanUp() + + cli := integrationtest.NewArduinoCliWithinEnvironment(t, &integrationtest.ArduinoCLIConfig{ + ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"), + UseSharedStagingFolder: true, + }, env) + defer cli.CleanUp() + + // Set up an http server to serve our custom index file + test_index := paths.New("..", "testdata", "test_index.json") + url, httpClose := integrationtest.HTTPServeFile(t, 8000, test_index) + defer httpClose() + + // Run update-index with our test index + _, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String()) + require.NoError(t, err) + + // Search a specific core + out, _, err := cli.Run("core", "search", "avr") + require.NoError(t, err) + require.Greater(t, len(strings.Split(string(out), "\n")), 2) + + out, _, err = cli.Run("core", "search", "avr", "--format", "json") + require.NoError(t, err) + data := make([]interface{}, 0) + require.NoError(t, json.Unmarshal(out, &data)) + require.NotEmpty(t, data) + // same check using gjson lib + require.NotEmpty(t, gjson.ParseBytes(out).Array()) + + // additional URL + out, _, err = cli.Run("core", "search", "test_core", "--format", "json", "--additional-urls="+url.String()) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(out, &data)) + require.Len(t, data, 1) + + // show all versions + out, _, err = cli.Run("core", "search", "test_core", "--all", "--format", "json", "--additional-urls="+url.String()) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(out, &data)) + require.Len(t, data, 2) + // alternative check using gjson: + require.Len(t, gjson.ParseBytes(out).Array(), 2) + // alternative using gojq: + integrationtest.JQQuery(t, out, "length", 2) + + checkPlatformIsInJSONOutput := func(stdout []byte, id, version string) { + // Alternative solution with gojq + jqquery := fmt.Sprintf(`contains( [{id:"%s", latest:"%s"}] )`, id, version) + integrationtest.JQQuery(t, out, jqquery, true, "platform %s@%s is missing from the output", id, version) + + // Alternative solution with gjson + // query := fmt.Sprintf("#(id=%s)#|#(latest=%s)", id, version) + // if gjson.ParseBytes(out).Get(query).Exists() { + // return + // } + // require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version) + + // Alternative solution: + // for _, platform := range gjson.ParseBytes(out).Array() { + // if platform.Get("id").Str == id && platform.Get("latest").Str == version { + // return + // } + // } + // require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version) + } + + // Search all Retrokit platforms + out, _, err = cli.Run("core", "search", "retrokit", "--all", "--additional-urls="+url.String(), "--format", "json") + require.NoError(t, err) + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5") + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6") + //checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.9") // Test failure + + // Search using Retrokit Package Maintainer + out, _, err = cli.Run("core", "search", "Retrokits-RK002", "--all", "--additional-urls="+url.String(), "--format", "json") + require.NoError(t, err) + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5") + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6") + + // Search using the Retrokit Platform name + out, _, err = cli.Run("core", "search", "rk002", "--all", "--additional-urls="+url.String(), "--format", "json") + require.NoError(t, err) + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5") + checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6") + + // Search using board names + out, _, err = cli.Run("core", "search", "myboard", "--all", "--additional-urls="+url.String(), "--format", "json") + require.NoError(t, err) + checkPlatformIsInJSONOutput(out, "Package:x86", "1.2.3") + + // Check search with case, accents and spaces + runSearch := func(searchArgs string, expectedIDs ...string) { + args := []string{"core", "search", "--format", "json"} + args = append(args, strings.Split(searchArgs, " ")...) + out, _, err := cli.Run(args...) + require.NoError(t, err) + + // Alternative solution with gojq + for _, id := range expectedIDs { + jqquery := fmt.Sprintf(`contains( [{id:"%s"}] )`, id) + integrationtest.JQQuery(t, out, jqquery, true, "platform %s is missing from the output", id) + } + + // Alternative solution with gjson + // data := gjson.ParseBytes(out) + // for _, expectedID := range expectedIDs { + // query := fmt.Sprintf("#(id=%s)", expectedID) + // if !data.Get(query).Exists() { + // require.FailNowf(t, "Wrong output", "platform %s is missing from the output", expectedID) + // } + // } + } + + runSearch("mkr1000", "arduino:samd") + runSearch("mkr 1000", "arduino:samd") + + runSearch("yún", "arduino:avr") + runSearch("yùn", "arduino:avr") + runSearch("yun", "arduino:avr") + + runSearch("nano 33", "arduino:samd", "arduino:mbed_nano") + runSearch("nano ble", "arduino:mbed_nano") + runSearch("ble", "arduino:mbed_nano") + runSearch("ble nano", "arduino:mbed_nano") + runSearch("nano", "arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano") +} diff --git a/internal/integrationtest/testdata/test_index.json b/internal/integrationtest/testdata/test_index.json new file mode 100644 index 00000000000..f5b5c6c35bd --- /dev/null +++ b/internal/integrationtest/testdata/test_index.json @@ -0,0 +1,210 @@ +{ + "packages": [ + { + "maintainer": "Arduino", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "websiteURL": "https://github.com/Arduino/arduino-cli", + "platforms": [ + { + "category": "Test Category", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip", + "checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", + "name": "test_core", + "version": "1.0.0", + "architecture": "x86", + "archiveFileName": "core.zip", + "size": "486", + "toolsDependencies": [], + "boards": [ + { + "name": "Test Board" + } + ] + }, + { + "category": "Test Category", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip", + "checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", + "name": "test_core", + "version": "2.0.0", + "architecture": "x86", + "archiveFileName": "core.zip", + "size": "486", + "toolsDependencies": [], + "boards": [ + { + "name": "Test Board" + } + ] + } + ], + "tools": [], + "email": "test@example.com", + "name": "test" + }, + { + "name": "zipslip", + "tools": [], + "email": "test@example.com", + "maintainer": "Arduino", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "websiteURL": "https://github.com/Arduino/arduino-cli", + "platforms": [ + { + "category": "Zipslip Test", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/evil.zip", + "checksum": "SHA-256:9b85dfe23f13318efc0e541327f584a0f3674a773d46a7eb8b25f0f408d07f96", + "name": "zipslip", + "version": "1.0.0", + "architecture": "x86", + "archiveFileName": "evil.zip", + "size": "2184", + "toolsDependencies": [], + "boards": [ + { + "name": "Test Board" + } + ] + } + ] + }, + { + "name": "brokenchecksum", + "tools": [], + "email": "test@example.com", + "maintainer": "Arduino", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "websiteURL": "https://github.com/Arduino/arduino-cli", + "platforms": [ + { + "category": "BrokenChecksum Test", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip", + "checksum": "SHA-256:1a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", + "name": "zipslip", + "version": "1.0.0", + "architecture": "x86", + "archiveFileName": "core.zip", + "size": "486", + "toolsDependencies": [], + "boards": [ + { + "name": "Test Board" + } + ] + } + ] + }, + { + "name": "Retrokits-RK002", + "maintainer": "Retrokits (www.retrokits.com)", + "websiteURL": "https://www.retrokits.com", + "email": "info@retrokits.com", + "help": { "online": "https://www.retrokits.com/rk002/arduino" }, + "platforms": [ + { + "name": "RK002", + "architecture": "arm", + "version": "1.0.5", + "category": "Contributed", + "help": { + "online": "https://www.retrokits.com/rk002/arduino" + }, + "url": "https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.5.tar.bz2", + "archiveFileName": "retrokits-rk002-1.0.5.tar.bz2", + "checksum": "SHA-256:9a012867baf4bb26f656f84502e0acce6a653c3452cca4505ebac77256802fb6", + "size": "290784", + "boards": [{ "name": "RK002" }], + "toolsDependencies": [ + { + "packager": "arduino", + "version": "4.8.3-2014q1", + "name": "arm-none-eabi-gcc" + } + ] + } + ], + "tools": [] + }, + { + "name": "Retrokits-RK002", + "maintainer": "Retrokits (www.retrokits.com)", + "websiteURL": "https://www.retrokits.com", + "email": "info@retrokits.com", + "help": { "online": "https://www.retrokits.com/rk002/arduino" }, + "platforms": [ + { + "name": "RK002", + "architecture": "arm", + "version": "1.0.6", + "category": "Contributed", + "help": { + "online": "https://www.retrokits.com/rk002/arduino" + }, + "url": "https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.6.tar.bz2", + "archiveFileName": "retrokits-rk002-1.0.6.tar.bz2", + "checksum": "SHA-256:8a3b63efcf4dfaed047a37844861387e542d8519485b5305d5979630cb3feb20", + "size": "291631", + "boards": [{ "name": "RK002" }], + "toolsDependencies": [ + { + "packager": "arduino", + "version": "4.8.3-2014q1", + "name": "arm-none-eabi-gcc" + } + ] + } + ], + "tools": [] + }, + { + "name": "Package", + "tools": [], + "email": "test@example.com", + "maintainer": "Arduino", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "websiteURL": "https://github.com/Arduino/arduino-cli", + "platforms": [ + { + "category": "Test", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip", + "checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", + "name": "Platform", + "version": "1.2.3", + "deprecated": true, + "architecture": "x86", + "archiveFileName": "core.zip", + "size": "486", + "toolsDependencies": [], + "boards": [ + { + "name": "MyBoard" + } + ] + } + ] + } + ] +} From eac13563406835e940589a9760d9eb02c14efc05 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Jul 2022 10:53:07 +0200 Subject: [PATCH 13/33] REMOVEME: Deactivate daemon integration test for now --- internal/integrationtest/arduino-cli_daemon_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/integrationtest/arduino-cli_daemon_test.go b/internal/integrationtest/arduino-cli_daemon_test.go index 8b0f609b0eb..40c17de7a71 100644 --- a/internal/integrationtest/arduino-cli_daemon_test.go +++ b/internal/integrationtest/arduino-cli_daemon_test.go @@ -28,6 +28,9 @@ import ( ) func TestArduinoCliDaemon(t *testing.T) { + t.Skip("Deactivated for now") + t.SkipNow() + env := NewEnvironment(t) defer env.CleanUp() From 2631e969fc7b501be03452283c4812549727cc42 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Jul 2022 11:06:54 +0200 Subject: [PATCH 14/33] testsuite: force colored output --- internal/integrationtest/arduino-cli.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 30fd5729328..0dc36778165 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -54,6 +54,7 @@ type ArduinoCLIConfig struct { // NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. func NewArduinoCliWithinEnvironment(t *testing.T, config *ArduinoCLIConfig, env *Environment) *ArduinoCLI { + color.NoColor = false cli := NewArduinoCli(t, config) staging := env.downloadsDir if !config.UseSharedStagingFolder { From 330b51d82079dc71a64d3d148d7ba7c1ed4e3341 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Aug 2022 11:35:08 +0200 Subject: [PATCH 15/33] testsuite: moved all generic subroutines into their own library --- arduino/discovery/discovery_client/go.sum | 9 +- client_example/go.sum | 7 +- docsgen/go.sum | 9 +- go.mod | 10 +- go.sum | 13 +- internal/integrationtest/arduino-cli.go | 14 +- .../arduino-cli_daemon_test.go | 8 +- internal/integrationtest/core/core_test.go | 65 ++------- internal/integrationtest/env.go | 129 ------------------ internal/integrationtest/http.go | 49 ------- internal/integrationtest/json.go | 40 ------ 11 files changed, 49 insertions(+), 304 deletions(-) delete mode 100644 internal/integrationtest/env.go delete mode 100644 internal/integrationtest/http.go delete mode 100644 internal/integrationtest/json.go diff --git a/arduino/discovery/discovery_client/go.sum b/arduino/discovery/discovery_client/go.sum index 9c93f57bba3..9368868ab9a 100644 --- a/arduino/discovery/discovery_client/go.sum +++ b/arduino/discovery/discovery_client/go.sum @@ -292,17 +292,17 @@ github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jW github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -314,6 +314,7 @@ go.bug.st/downloader/v2 v2.1.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13R go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16ijss7Q= go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw= +go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= diff --git a/client_example/go.sum b/client_example/go.sum index 4ea6136f5f0..eb7d580b185 100644 --- a/client_example/go.sum +++ b/client_example/go.sum @@ -275,16 +275,16 @@ github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jW github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -296,6 +296,7 @@ go.bug.st/downloader/v2 v2.1.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13R go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16ijss7Q= go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw= +go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= diff --git a/docsgen/go.sum b/docsgen/go.sum index bd15643e3a5..5a115fd1b8c 100644 --- a/docsgen/go.sum +++ b/docsgen/go.sum @@ -343,18 +343,18 @@ github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jW github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -372,6 +372,7 @@ go.bug.st/serial v1.3.2 h1:6BFZZd/wngoL5PPYYTrFUounF54SIkykHpT98eq6zvk= go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw= +go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= diff --git a/go.mod b/go.mod index 121b55f4275..305d9f33131 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/spf13/cobra v1.2.1 github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.8.1 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.0 go.bug.st/cleanup v1.0.0 go.bug.st/downloader/v2 v2.1.1 go.bug.st/relaxed-semver v0.9.0 @@ -57,10 +57,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) -require ( - github.com/itchyny/gojq v0.12.8 - github.com/tidwall/gjson v1.14.1 -) +require go.bug.st/testsuite v0.0.1 require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect @@ -71,6 +68,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/itchyny/gojq v0.12.8 // indirect github.com/itchyny/timefmt-go v0.1.3 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -90,8 +88,6 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/src-d/gcfg v1.4.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect - github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/pretty v1.2.0 // indirect github.com/xanzy/ssh-agent v0.2.1 // indirect golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect gopkg.in/ini.v1 v1.62.0 // indirect diff --git a/go.sum b/go.sum index 19232321d69..d4ba7f0c551 100644 --- a/go.sum +++ b/go.sum @@ -345,21 +345,18 @@ github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jW github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= -github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -377,6 +374,8 @@ go.bug.st/serial v1.3.2 h1:6BFZZd/wngoL5PPYYTrFUounF54SIkykHpT98eq6zvk= go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw= +go.bug.st/testsuite v0.0.1 h1:sdB+u46r+9ZVqROU1fl5utU773HktWDSc4hz6/jPK6A= +go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 0dc36778165..e6706b9ff7a 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -31,6 +31,7 @@ import ( "github.com/arduino/go-paths-helper" "github.com/fatih/color" "github.com/stretchr/testify/require" + "go.bug.st/testsuite" "google.golang.org/grpc" ) @@ -53,18 +54,19 @@ type ArduinoCLIConfig struct { } // NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. -func NewArduinoCliWithinEnvironment(t *testing.T, config *ArduinoCLIConfig, env *Environment) *ArduinoCLI { +func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoCLIConfig) *ArduinoCLI { color.NoColor = false - cli := NewArduinoCli(t, config) - staging := env.downloadsDir + cli := NewArduinoCli(env.T(), config) + staging := env.SharedDownloadsDir() if !config.UseSharedStagingFolder { - staging = env.Root().Join("arduino15/staging") + staging = env.RootDir().Join("arduino15/staging") } cli.cliEnvVars = []string{ - fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.Root().Join("arduino15")), + fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.RootDir().Join("arduino15")), fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", staging), - fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.Root().Join("Arduino")), + fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.RootDir().Join("Arduino")), } + env.RegisterCleanUpCallback(cli.CleanUp) return cli } diff --git a/internal/integrationtest/arduino-cli_daemon_test.go b/internal/integrationtest/arduino-cli_daemon_test.go index 40c17de7a71..3485eaa3b96 100644 --- a/internal/integrationtest/arduino-cli_daemon_test.go +++ b/internal/integrationtest/arduino-cli_daemon_test.go @@ -25,20 +25,20 @@ import ( "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" + "go.bug.st/testsuite" ) func TestArduinoCliDaemon(t *testing.T) { t.Skip("Deactivated for now") t.SkipNow() - env := NewEnvironment(t) + env := testsuite.NewEnvironment(t) defer env.CleanUp() - cli := NewArduinoCliWithinEnvironment(t, &ArduinoCLIConfig{ + cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{ ArduinoCLIPath: paths.New("..", "..", "arduino-cli"), UseSharedStagingFolder: true, - }, env) - defer cli.CleanUp() + }) _, _, err := cli.Run("core", "update-index") require.NoError(t, err) diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index 76730cacbb2..ee55c688597 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -16,7 +16,6 @@ package core_test import ( - "encoding/json" "fmt" "strings" "testing" @@ -24,23 +23,22 @@ import ( "github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" - "github.com/tidwall/gjson" + "go.bug.st/testsuite" + "go.bug.st/testsuite/requirejson" ) func TestCoreSearch(t *testing.T) { - env := integrationtest.NewEnvironment(t) + env := testsuite.NewEnvironment(t) defer env.CleanUp() - cli := integrationtest.NewArduinoCliWithinEnvironment(t, &integrationtest.ArduinoCLIConfig{ + cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{ ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"), UseSharedStagingFolder: true, - }, env) - defer cli.CleanUp() + }) // Set up an http server to serve our custom index file test_index := paths.New("..", "testdata", "test_index.json") - url, httpClose := integrationtest.HTTPServeFile(t, 8000, test_index) - defer httpClose() + url := env.HTTPServeFile(8000, test_index) // Run update-index with our test index _, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String()) @@ -53,47 +51,22 @@ func TestCoreSearch(t *testing.T) { out, _, err = cli.Run("core", "search", "avr", "--format", "json") require.NoError(t, err) - data := make([]interface{}, 0) - require.NoError(t, json.Unmarshal(out, &data)) - require.NotEmpty(t, data) - // same check using gjson lib - require.NotEmpty(t, gjson.ParseBytes(out).Array()) + requirejson.NotEmpty(t, out) // additional URL out, _, err = cli.Run("core", "search", "test_core", "--format", "json", "--additional-urls="+url.String()) require.NoError(t, err) - require.NoError(t, json.Unmarshal(out, &data)) - require.Len(t, data, 1) + requirejson.Len(t, out, 1) // show all versions out, _, err = cli.Run("core", "search", "test_core", "--all", "--format", "json", "--additional-urls="+url.String()) require.NoError(t, err) - require.NoError(t, json.Unmarshal(out, &data)) - require.Len(t, data, 2) - // alternative check using gjson: - require.Len(t, gjson.ParseBytes(out).Array(), 2) - // alternative using gojq: - integrationtest.JQQuery(t, out, "length", 2) + requirejson.Len(t, out, 2) + // requirejson.Len(t, out, 3) // Test failure checkPlatformIsInJSONOutput := func(stdout []byte, id, version string) { - // Alternative solution with gojq - jqquery := fmt.Sprintf(`contains( [{id:"%s", latest:"%s"}] )`, id, version) - integrationtest.JQQuery(t, out, jqquery, true, "platform %s@%s is missing from the output", id, version) - - // Alternative solution with gjson - // query := fmt.Sprintf("#(id=%s)#|#(latest=%s)", id, version) - // if gjson.ParseBytes(out).Get(query).Exists() { - // return - // } - // require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version) - - // Alternative solution: - // for _, platform := range gjson.ParseBytes(out).Array() { - // if platform.Get("id").Str == id && platform.Get("latest").Str == version { - // return - // } - // } - // require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version) + jqquery := fmt.Sprintf(`[{id:"%s", latest:"%s"}]`, id, version) + requirejson.Contains(t, out, jqquery, "platform %s@%s is missing from the output", id, version) } // Search all Retrokit platforms @@ -127,20 +100,10 @@ func TestCoreSearch(t *testing.T) { out, _, err := cli.Run(args...) require.NoError(t, err) - // Alternative solution with gojq for _, id := range expectedIDs { - jqquery := fmt.Sprintf(`contains( [{id:"%s"}] )`, id) - integrationtest.JQQuery(t, out, jqquery, true, "platform %s is missing from the output", id) + jqquery := fmt.Sprintf(`[{id:"%s"}]`, id) + requirejson.Contains(t, out, jqquery, "platform %s is missing from the output", id) } - - // Alternative solution with gjson - // data := gjson.ParseBytes(out) - // for _, expectedID := range expectedIDs { - // query := fmt.Sprintf("#(id=%s)", expectedID) - // if !data.Get(query).Exists() { - // require.FailNowf(t, "Wrong output", "platform %s is missing from the output", expectedID) - // } - // } } runSearch("mkr1000", "arduino:samd") diff --git a/internal/integrationtest/env.go b/internal/integrationtest/env.go deleted file mode 100644 index 55675805e3f..00000000000 --- a/internal/integrationtest/env.go +++ /dev/null @@ -1,129 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package integrationtest - -import ( - "context" - "crypto/md5" - "encoding/hex" - "io" - "net/http" - "net/url" - "path/filepath" - "testing" - - "github.com/arduino/go-paths-helper" - "github.com/codeclysm/extract/v3" - "github.com/stretchr/testify/require" -) - -// Environment is a test environment for the test suite. -type Environment struct { - rootDir *paths.Path - downloadsDir *paths.Path - t *require.Assertions -} - -// SharedDownloadDir returns the shared downloads directory. -func SharedDownloadDir(t *testing.T) *paths.Path { - downloadsDir := paths.TempDir().Join("arduino-cli-test-suite-staging") - require.NoError(t, downloadsDir.MkdirAll()) - return downloadsDir -} - -// NewEnvironment creates a new test environment. -func NewEnvironment(t *testing.T) *Environment { - downloadsDir := SharedDownloadDir(t) - rootDir, err := paths.MkTempDir("", "arduino-cli-test-suite") - require.NoError(t, err) - return &Environment{ - rootDir: rootDir, - downloadsDir: downloadsDir, - t: require.New(t), - } -} - -// CleanUp removes the test environment. -func (e *Environment) CleanUp() { - e.t.NoError(e.rootDir.RemoveAll()) -} - -// Root returns the root dir of the environment. -func (e *Environment) Root() *paths.Path { - return e.rootDir -} - -// Download downloads a file from a URL and returns the path to the downloaded file. -// The file is saved and cached in a shared downloads directory. If the file already exists, it is not downloaded again. -func (e *Environment) Download(rawURL string) *paths.Path { - url, err := url.Parse(rawURL) - e.t.NoError(err) - - filename := filepath.Base(url.Path) - if filename == "/" { - filename = "" - } else { - filename = "-" + filename - } - - hash := md5.Sum([]byte(rawURL)) - resource := e.downloadsDir.Join(hex.EncodeToString(hash[:]) + filename) - - // If the resource already exist, return it - if resource.Exist() { - return resource - } - - // Download file - resp, err := http.Get(rawURL) - e.t.NoError(err) - defer resp.Body.Close() - - // Copy data in a temp file - tmp := resource.Parent().Join(resource.Base() + ".tmp") - out, err := tmp.Create() - e.t.NoError(err) - defer tmp.Remove() - defer out.Close() - - // Write the body to file - _, err = io.Copy(out, resp.Body) - e.t.NoError(err) - e.t.NoError(out.Close()) - - // Rename the file to its final destination - e.t.NoError(tmp.Rename(resource)) - - return resource -} - -// Extract extracts a tarball to a directory named as the archive -// with the "_content" suffix added. Returns the path to the directory. -func (e *Environment) Extract(archive *paths.Path) *paths.Path { - destDir := archive.Parent().Join(archive.Base() + "_content") - if destDir.Exist() { - return destDir - } - - file, err := archive.Open() - e.t.NoError(err) - defer file.Close() - - err = extract.Archive(context.Background(), file, destDir.String(), nil) - e.t.NoError(err) - - return destDir -} diff --git a/internal/integrationtest/http.go b/internal/integrationtest/http.go deleted file mode 100644 index d81590186bb..00000000000 --- a/internal/integrationtest/http.go +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package integrationtest - -import ( - "fmt" - "net/http" - "net/url" - "testing" - - "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -// HTTPServeFile spawn an http server that serve a single file. The server -// is started on the given port. The URL to the file and a cleanup function are returned. -func HTTPServeFile(t *testing.T, port uint16, path *paths.Path) (*url.URL, func()) { - mux := http.NewServeMux() - mux.HandleFunc("/"+path.Base(), func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, path.String()) - }) - server := &http.Server{ - Addr: fmt.Sprintf(":%d", port), - Handler: mux, - } - - fileURL, err := url.Parse(fmt.Sprintf("http://127.0.0.1:%d/%s", port, path.Base())) - require.NoError(t, err) - - go func() { - err := server.ListenAndServe() - require.Equal(t, err, http.ErrServerClosed) - }() - - return fileURL, func() { server.Close() } -} diff --git a/internal/integrationtest/json.go b/internal/integrationtest/json.go deleted file mode 100644 index d11c2db1cd1..00000000000 --- a/internal/integrationtest/json.go +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package integrationtest - -import ( - "encoding/json" - "testing" - - "github.com/itchyny/gojq" - "github.com/stretchr/testify/require" -) - -// JQQuery performs a test on a given json output. A jq-like query is performed -// on the given jsonData and the result is compared with the expected output. -// If the output doesn't match the test fails. If msgAndArgs are provided they -// will be used to explain the error. -func JQQuery(t *testing.T, jsonData []byte, jqQuery string, expected interface{}, msgAndArgs ...interface{}) { - var data interface{} - require.NoError(t, json.Unmarshal(jsonData, &data)) - q, err := gojq.Parse(jqQuery) - require.NoError(t, err) - i := q.Run(data) - v, ok := i.Next() - require.True(t, ok) - require.IsType(t, expected, v) - require.Equal(t, expected, v, msgAndArgs...) -} From b886381b815b72d9801a65d78f4f7d5c4ac4666c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Aug 2022 11:39:12 +0200 Subject: [PATCH 16/33] testsuite: moved daemon test in his own dir --- .../integrationtest/{ => daemon}/arduino-cli_daemon_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename internal/integrationtest/{ => daemon}/arduino-cli_daemon_test.go (94%) diff --git a/internal/integrationtest/arduino-cli_daemon_test.go b/internal/integrationtest/daemon/arduino-cli_daemon_test.go similarity index 94% rename from internal/integrationtest/arduino-cli_daemon_test.go rename to internal/integrationtest/daemon/arduino-cli_daemon_test.go index 3485eaa3b96..8f13c61bdc5 100644 --- a/internal/integrationtest/arduino-cli_daemon_test.go +++ b/internal/integrationtest/daemon/arduino-cli_daemon_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" @@ -35,7 +36,7 @@ func TestArduinoCliDaemon(t *testing.T) { env := testsuite.NewEnvironment(t) defer env.CleanUp() - cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{ + cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{ ArduinoCLIPath: paths.New("..", "..", "arduino-cli"), UseSharedStagingFolder: true, }) From a9d73c213d7514c9ef2da05ae139c0839a847a78 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Aug 2022 11:39:36 +0200 Subject: [PATCH 17/33] fixed typo --- internal/integrationtest/arduino-cli.go | 4 ++-- internal/integrationtest/daemon/arduino-cli_daemon_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index e6706b9ff7a..fb8cd1d2e69 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -122,8 +122,8 @@ func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { return stdoutBuf.Bytes(), stderrBuf.Bytes(), cliErr } -// StartDeamon starts the Arduino CLI daemon. It returns the address of the daemon. -func (cli *ArduinoCLI) StartDeamon(verbose bool) string { +// StartDaemon starts the Arduino CLI daemon. It returns the address of the daemon. +func (cli *ArduinoCLI) StartDaemon(verbose bool) string { args := []string{"daemon", "--format", "json"} if cli.cliConfigPath != nil { args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...) diff --git a/internal/integrationtest/daemon/arduino-cli_daemon_test.go b/internal/integrationtest/daemon/arduino-cli_daemon_test.go index 8f13c61bdc5..7e120aed61c 100644 --- a/internal/integrationtest/daemon/arduino-cli_daemon_test.go +++ b/internal/integrationtest/daemon/arduino-cli_daemon_test.go @@ -44,7 +44,7 @@ func TestArduinoCliDaemon(t *testing.T) { _, _, err := cli.Run("core", "update-index") require.NoError(t, err) - _ = cli.StartDeamon(false) + _ = cli.StartDaemon(false) inst := cli.Create() require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { From f3c14633d8ef50ab4ccaa004d9315c123aba9592 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Aug 2022 17:28:45 +0200 Subject: [PATCH 18/33] testsuite: added some helpers to improve daemon testing --- internal/integrationtest/arduino-cli.go | 42 ++++++++++++------- .../daemon/arduino-cli_daemon_test.go | 15 +------ .../integrationtest/daemon/daemon_test.go | 40 ++++++++++++++++++ 3 files changed, 68 insertions(+), 29 deletions(-) create mode 100644 internal/integrationtest/daemon/daemon_test.go diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index fb8cd1d2e69..bd869db8971 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -23,7 +23,6 @@ import ( "os" "strings" "sync" - "testing" "time" "github.com/arduino/arduino-cli/executils" @@ -42,6 +41,9 @@ type ArduinoCLI struct { proc *executils.Process cliEnvVars []string cliConfigPath *paths.Path + stagingDir *paths.Path + dataDir *paths.Path + sketchbookDir *paths.Path daemonAddr string daemonConn *grpc.ClientConn daemonClient commands.ArduinoCoreServiceClient @@ -56,28 +58,26 @@ type ArduinoCLIConfig struct { // NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment. func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoCLIConfig) *ArduinoCLI { color.NoColor = false - cli := NewArduinoCli(env.T(), config) - staging := env.SharedDownloadsDir() - if !config.UseSharedStagingFolder { - staging = env.RootDir().Join("arduino15/staging") + cli := &ArduinoCLI{ + path: config.ArduinoCLIPath, + t: require.New(env.T()), + dataDir: env.RootDir().Join("arduino15"), + sketchbookDir: env.RootDir().Join("Arduino"), + stagingDir: env.RootDir().Join("arduino15/staging"), } + if config.UseSharedStagingFolder { + cli.stagingDir = env.SharedDownloadsDir() + } + cli.cliEnvVars = []string{ - fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.RootDir().Join("arduino15")), - fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", staging), - fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.RootDir().Join("Arduino")), + fmt.Sprintf("ARDUINO_DATA_DIR=%s", cli.dataDir), + fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", cli.stagingDir), + fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", cli.sketchbookDir), } env.RegisterCleanUpCallback(cli.CleanUp) return cli } -// NewArduinoCli creates a new Arduino CLI client. -func NewArduinoCli(t *testing.T, config *ArduinoCLIConfig) *ArduinoCLI { - return &ArduinoCLI{ - path: config.ArduinoCLIPath, - t: require.New(t), - } -} - // CleanUp closes the Arduino CLI client. func (cli *ArduinoCLI) CleanUp() { if cli.proc != nil { @@ -86,6 +86,16 @@ func (cli *ArduinoCLI) CleanUp() { } } +// DataDir returns the data directory +func (cli *ArduinoCLI) DataDir() *paths.Path { + return cli.dataDir +} + +// SketchbookDir returns the sketchbook directory +func (cli *ArduinoCLI) SketchbookDir() *paths.Path { + return cli.sketchbookDir +} + // Run executes the given arduino-cli command and returns the output. func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) { if cli.cliConfigPath != nil { diff --git a/internal/integrationtest/daemon/arduino-cli_daemon_test.go b/internal/integrationtest/daemon/arduino-cli_daemon_test.go index 7e120aed61c..08a16a3bd99 100644 --- a/internal/integrationtest/daemon/arduino-cli_daemon_test.go +++ b/internal/integrationtest/daemon/arduino-cli_daemon_test.go @@ -13,7 +13,7 @@ // Arduino software without disclosing the source code of your own applications. // To purchase a commercial license, send an email to license@arduino.cc. -package integrationtest +package daemon_test import ( "context" @@ -22,28 +22,17 @@ import ( "testing" "time" - "github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" - "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" - "go.bug.st/testsuite" ) func TestArduinoCliDaemon(t *testing.T) { t.Skip("Deactivated for now") t.SkipNow() - env := testsuite.NewEnvironment(t) + env, cli := createEnvForDaemon(t) defer env.CleanUp() - cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{ - ArduinoCLIPath: paths.New("..", "..", "arduino-cli"), - UseSharedStagingFolder: true, - }) - - _, _, err := cli.Run("core", "update-index") - require.NoError(t, err) - _ = cli.StartDaemon(false) inst := cli.Create() diff --git a/internal/integrationtest/daemon/daemon_test.go b/internal/integrationtest/daemon/daemon_test.go new file mode 100644 index 00000000000..8d5e0f6886c --- /dev/null +++ b/internal/integrationtest/daemon/daemon_test.go @@ -0,0 +1,40 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package daemon_test + +import ( + "testing" + + "github.com/arduino/arduino-cli/internal/integrationtest" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" + "go.bug.st/testsuite" +) + +func createEnvForDaemon(t *testing.T) (*testsuite.Environment, *integrationtest.ArduinoCLI) { + env := testsuite.NewEnvironment(t) + + cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{ + ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"), + UseSharedStagingFolder: true, + }) + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + + _ = cli.StartDaemon(false) + return env, cli +} From 94ba9ac2d426693c27d7bde19380d69f26921464 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Aug 2022 17:29:56 +0200 Subject: [PATCH 19/33] testsuite: added test for #1614 --- internal/integrationtest/arduino-cli.go | 23 +++++ .../daemon/daemon_compile_test.go | 98 +++++++++++++++++++ .../testdata/bare_minimum/bare_minimum.ino | 2 + .../testdata/boards.local.txt-issue1614 | 10 ++ 4 files changed, 133 insertions(+) create mode 100644 internal/integrationtest/daemon/daemon_compile_test.go create mode 100644 internal/integrationtest/daemon/testdata/bare_minimum/bare_minimum.ino create mode 100644 internal/integrationtest/daemon/testdata/boards.local.txt-issue1614 diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index bd869db8971..686be4e46f8 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -259,3 +259,26 @@ func (inst *ArduinoCLIInstance) BoardListWatch() (commands.ArduinoCoreService_Bo } return watcher, watcher.Send(boardListWatchReq) } + +// PlatformInstall calls the "PlatformInstall" gRPC method. +func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, arch, version string) (commands.ArduinoCoreService_PlatformInstallClient, error) { + installCl, err := inst.cli.daemonClient.PlatformInstall(ctx, &commands.PlatformInstallRequest{ + Instance: inst.instance, + PlatformPackage: packager, + Architecture: arch, + Version: version, + }) + logCallf(">>> PlatformInstall(%v:%v %v)\n", packager, arch, version) + return installCl, err +} + +func (inst *ArduinoCLIInstance) Compile(ctx context.Context, fqbn, sketchPath string) (commands.ArduinoCoreService_CompileClient, error) { + compileCl, err := inst.cli.daemonClient.Compile(ctx, &commands.CompileRequest{ + Instance: inst.instance, + Fqbn: fqbn, + SketchPath: sketchPath, + Verbose: true, + }) + logCallf(">>> Compile(%v %v)\n", fqbn, sketchPath) + return compileCl, err +} diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go new file mode 100644 index 00000000000..18534af432a --- /dev/null +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -0,0 +1,98 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package daemon_test + +import ( + "context" + "fmt" + "io" + "testing" + + "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +func TestDaemonCompileOptions(t *testing.T) { + env, cli := createEnvForDaemon(t) + defer env.CleanUp() + + inst := cli.Create() + require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + fmt.Printf("INIT> %v\n", ir.GetMessage()) + })) + + plInst, err := inst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5") + require.NoError(t, err) + for { + msg, err := plInst.Recv() + if err == io.EOF { + break + } + require.NoError(t, err) + fmt.Printf("INSTALL> %v\n", msg) + } + + // Install boards.local.txt to trigger bug + platformLocalTxt := paths.New("testdata", "boards.local.txt-issue1614") + err = platformLocalTxt.CopyTo(cli.DataDir(). + Join("packages", "arduino", "hardware", "avr", "1.8.5", "boards.local.txt")) + require.NoError(t, err) + + // Re-init instance to update changes + require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + fmt.Printf("INIT> %v\n", ir.GetMessage()) + })) + + // Build sketch (with errors) + sk := paths.New("testdata", "bare_minimum") + compile, err := inst.Compile(context.Background(), "arduino:avr:uno:some_menu=bad", sk.String()) + require.NoError(t, err) + for { + msg, err := compile.Recv() + if err == io.EOF { + require.FailNow(t, "Expected compilation failure", "compilation succeeded") + break + } + if err != nil { + fmt.Println("COMPILE ERROR>", err) + break + } + // if msg.OutStream != nil { + // fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream())) + // } + if msg.ErrStream != nil { + fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) + } + } + + // Build sketch (without errors) + compile, err = inst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String()) + require.NoError(t, err) + for { + msg, err := compile.Recv() + if err == io.EOF { + break + } + require.NoError(t, err) + // if msg.OutStream != nil { + // fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream())) + // } + if msg.ErrStream != nil { + fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) + } + } +} diff --git a/internal/integrationtest/daemon/testdata/bare_minimum/bare_minimum.ino b/internal/integrationtest/daemon/testdata/bare_minimum/bare_minimum.ino new file mode 100644 index 00000000000..660bdbccfdb --- /dev/null +++ b/internal/integrationtest/daemon/testdata/bare_minimum/bare_minimum.ino @@ -0,0 +1,2 @@ +void setup() {} +void loop() {} diff --git a/internal/integrationtest/daemon/testdata/boards.local.txt-issue1614 b/internal/integrationtest/daemon/testdata/boards.local.txt-issue1614 new file mode 100644 index 00000000000..5903185453c --- /dev/null +++ b/internal/integrationtest/daemon/testdata/boards.local.txt-issue1614 @@ -0,0 +1,10 @@ +# https://github.com/arduino/arduino-cli/issues/1614 + +menu.some_menu=Some Custom Menu + +uno.menu.some_menu.bad=Bad Option +uno.menu.some_menu.bad.build.extra_flags=-bad-build-extraflags +uno.menu.some_menu.bad.compiler.cpp.extra_flags=-bad-compiler-cpp-extraflags + +uno.menu.some_menu.good=Good Option +uno.menu.some_menu.good.compiler.cpp.extra_flags=-DGOOD_COMPILER_CPP_EXTRA_FLAGS From 688f7afb30bf30f06448901b1dea876a0898cf76 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:28:07 +0200 Subject: [PATCH 20/33] Removed converted test --- test/test_core.py | 82 ----------------------------------------------- 1 file changed, 82 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index fdf8a711ff5..748714f7c05 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -26,88 +26,6 @@ import semver -def test_core_search(run_command, httpserver): - # Set up the server to serve our custom index file - test_index = Path(__file__).parent / "testdata" / "test_index.json" - httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text()) - - url = httpserver.url_for("/test_index.json") - assert run_command(["core", "update-index", f"--additional-urls={url}"]) - # search a specific core - result = run_command(["core", "search", "avr"]) - assert result.ok - assert 2 < len(result.stdout.splitlines()) - result = run_command(["core", "search", "avr", "--format", "json"]) - assert result.ok - data = json.loads(result.stdout) - assert 0 < len(data) - # additional URL - result = run_command(["core", "search", "test_core", "--format", "json", f"--additional-urls={url}"]) - assert result.ok - data = json.loads(result.stdout) - assert 1 == len(data) - # show all versions - result = run_command(["core", "search", "test_core", "--all", "--format", "json", f"--additional-urls={url}"]) - assert result.ok - data = json.loads(result.stdout) - assert 2 == len(data) - - def get_platforms(stdout): - data = json.loads(stdout) - platforms = {p["id"]: [] for p in data} - for p in data: - platforms[p["id"]].append(p["latest"]) - return platforms - - # Search all Retrokit platforms - result = run_command(["core", "search", "retrokit", "--all", f"--additional-urls={url}", "--format", "json"]) - assert result.ok - platforms = get_platforms(result.stdout) - assert "1.0.5" in platforms["Retrokits-RK002:arm"] - assert "1.0.6" in platforms["Retrokits-RK002:arm"] - - # Search using Retrokit Package Maintainer - result = run_command(["core", "search", "Retrokits-RK002", "--all", f"--additional-urls={url}", "--format", "json"]) - assert result.ok - platforms = get_platforms(result.stdout) - assert "1.0.5" in platforms["Retrokits-RK002:arm"] - assert "1.0.6" in platforms["Retrokits-RK002:arm"] - - # Search using the Retrokit Platform name - result = run_command(["core", "search", "rk002", "--all", f"--additional-urls={url}", "--format", "json"]) - assert result.ok - platforms = get_platforms(result.stdout) - assert "1.0.5" in platforms["Retrokits-RK002:arm"] - assert "1.0.6" in platforms["Retrokits-RK002:arm"] - - # Search using board names - result = run_command(["core", "search", "myboard", "--all", f"--additional-urls={url}", "--format", "json"]) - assert result.ok - platforms = get_platforms(result.stdout) - assert "1.2.3" in platforms["Package:x86"] - - def run_search(search_args, expected_ids): - res = run_command(["core", "search", "--format", "json"] + search_args.split(" ")) - assert res.ok - data = json.loads(res.stdout) - platform_ids = [p["id"] for p in data] - for platform_id in expected_ids: - assert platform_id in platform_ids - - run_search("mkr1000", ["arduino:samd"]) - run_search("mkr 1000", ["arduino:samd"]) - - run_search("yún", ["arduino:avr"]) - run_search("yùn", ["arduino:avr"]) - run_search("yun", ["arduino:avr"]) - - run_search("nano", ["arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano"]) - run_search("nano 33", ["arduino:samd", "arduino:mbed_nano"]) - run_search("nano ble", ["arduino:mbed_nano"]) - run_search("ble", ["arduino:mbed_nano"]) - run_search("ble nano", ["arduino:mbed_nano"]) - - def test_core_search_no_args(run_command, httpserver): """ This tests `core search` with and without additional URLs in case no args From 9fea578dca6cf88d64478c102e563ff76c9e0171 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:36:52 +0200 Subject: [PATCH 21/33] testsuite: perform build before test Otherwise people running the task locally will have a bad time when the test either fails due to the missing executable, or far worse when they get incorrect test results because they don't realize it is using whichever random executable happened to be sitting around from the last time they did a build. --- .github/workflows/test-go-task.yml | 3 --- Taskfile.yml | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-go-task.yml b/.github/workflows/test-go-task.yml index decd3ff2c89..90df72399eb 100644 --- a/.github/workflows/test-go-task.yml +++ b/.github/workflows/test-go-task.yml @@ -89,9 +89,6 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x - - name: Build arduino-cli - run: task go:build - - name: Run tests run: task go:test diff --git a/Taskfile.yml b/Taskfile.yml index 801f21d620a..d3fd8b71b28 100755 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -90,7 +90,9 @@ tasks: # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml go:test: - desc: Run unit tests + desc: Run unit tests and part of the integration tests + deps: + - task: go:build dir: '{{default "./" .GO_MODULE_PATH}}' cmds: - | From 0c282cd98b28e288b7abd602c5f8caf2e9464571 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:39:49 +0200 Subject: [PATCH 22/33] Added missing comment --- internal/integrationtest/arduino-cli.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 686be4e46f8..937857171a0 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -272,6 +272,7 @@ func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, a return installCl, err } +// Compile calls the "Compile" gRPC method. func (inst *ArduinoCLIInstance) Compile(ctx context.Context, fqbn, sketchPath string) (commands.ArduinoCoreService_CompileClient, error) { compileCl, err := inst.cli.daemonClient.Compile(ctx, &commands.CompileRequest{ Instance: inst.instance, From 55833f876ca5ac9ed004e7bf54dc759ab62b5e70 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:50:50 +0200 Subject: [PATCH 23/33] Renamed test file --- .../{arduino-cli_daemon_test.go => daemon_board_watch_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename internal/integrationtest/daemon/{arduino-cli_daemon_test.go => daemon_board_watch_test.go} (100%) diff --git a/internal/integrationtest/daemon/arduino-cli_daemon_test.go b/internal/integrationtest/daemon/daemon_board_watch_test.go similarity index 100% rename from internal/integrationtest/daemon/arduino-cli_daemon_test.go rename to internal/integrationtest/daemon/daemon_board_watch_test.go From eea3ec91fe245c7aa21e5da34d9032ec7859d0bd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:53:06 +0200 Subject: [PATCH 24/33] Skip failing tests --- internal/integrationtest/daemon/daemon_board_watch_test.go | 5 +++-- internal/integrationtest/daemon/daemon_compile_test.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/integrationtest/daemon/daemon_board_watch_test.go b/internal/integrationtest/daemon/daemon_board_watch_test.go index 08a16a3bd99..4a76c6f084e 100644 --- a/internal/integrationtest/daemon/daemon_board_watch_test.go +++ b/internal/integrationtest/daemon/daemon_board_watch_test.go @@ -27,8 +27,9 @@ import ( ) func TestArduinoCliDaemon(t *testing.T) { - t.Skip("Deactivated for now") - t.SkipNow() + // See: https://github.com/arduino/arduino-cli/pull/1804 + + t.SkipNow() // TO BE Removed once the bug is fixed env, cli := createEnvForDaemon(t) defer env.CleanUp() diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go index 18534af432a..18516115a5f 100644 --- a/internal/integrationtest/daemon/daemon_compile_test.go +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -27,6 +27,11 @@ import ( ) func TestDaemonCompileOptions(t *testing.T) { + // See: https://github.com/arduino/arduino-cli/issues/1614 + // See: https://github.com/arduino/arduino-cli/pull/1820 + + t.SkipNow() // TO BE Removed once the bug is fixed + env, cli := createEnvForDaemon(t) defer env.CleanUp() From ca557acf1389968e30a6a30b4bd9345543a987c1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 10:57:27 +0200 Subject: [PATCH 25/33] Updated licensed cache --- .../go/github.com/mattn/go-isatty.dep.yml | 2 +- .../go/github.com/mattn/go-runewidth.dep.yml | 2 +- .licenses/go/github.com/rivo/uniseg.dep.yml | 33 +++++++++++++++++++ .../x/sys/internal/unsafeheader.dep.yml | 6 ++-- .licenses/go/golang.org/x/sys/unix.dep.yml | 6 ++-- 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .licenses/go/github.com/rivo/uniseg.dep.yml diff --git a/.licenses/go/github.com/mattn/go-isatty.dep.yml b/.licenses/go/github.com/mattn/go-isatty.dep.yml index de6b9c513ec..de6d423c45c 100644 --- a/.licenses/go/github.com/mattn/go-isatty.dep.yml +++ b/.licenses/go/github.com/mattn/go-isatty.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/mattn/go-isatty -version: v0.0.12 +version: v0.0.14 type: go summary: Package isatty implements interface to isatty homepage: https://pkg.go.dev/github.com/mattn/go-isatty diff --git a/.licenses/go/github.com/mattn/go-runewidth.dep.yml b/.licenses/go/github.com/mattn/go-runewidth.dep.yml index f7a5f482cf0..bf7fb170e93 100644 --- a/.licenses/go/github.com/mattn/go-runewidth.dep.yml +++ b/.licenses/go/github.com/mattn/go-runewidth.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/mattn/go-runewidth -version: v0.0.9 +version: v0.0.13 type: go summary: homepage: https://pkg.go.dev/github.com/mattn/go-runewidth diff --git a/.licenses/go/github.com/rivo/uniseg.dep.yml b/.licenses/go/github.com/rivo/uniseg.dep.yml new file mode 100644 index 00000000000..fe6b35ad6f3 --- /dev/null +++ b/.licenses/go/github.com/rivo/uniseg.dep.yml @@ -0,0 +1,33 @@ +--- +name: github.com/rivo/uniseg +version: v0.2.0 +type: go +summary: 'Package uniseg implements Unicode Text Segmentation according to Unicode + Standard Annex #29 (http://unicode.org/reports/tr29/).' +homepage: https://pkg.go.dev/github.com/rivo/uniseg +license: mit +licenses: +- sources: LICENSE.txt + text: | + MIT License + + Copyright (c) 2019 Oliver Kuederle + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +notices: [] diff --git a/.licenses/go/golang.org/x/sys/internal/unsafeheader.dep.yml b/.licenses/go/golang.org/x/sys/internal/unsafeheader.dep.yml index 0ee7231edfd..043976e8d4c 100644 --- a/.licenses/go/golang.org/x/sys/internal/unsafeheader.dep.yml +++ b/.licenses/go/golang.org/x/sys/internal/unsafeheader.dep.yml @@ -1,13 +1,13 @@ --- name: golang.org/x/sys/internal/unsafeheader -version: v0.0.0-20210823070655-63515b42dcdf +version: v0.0.0-20220520151302-bc2c85ada10a type: go summary: Package unsafeheader contains header declarations for the Go runtime's slice and string implementations. homepage: https://pkg.go.dev/golang.org/x/sys/internal/unsafeheader license: bsd-3-clause licenses: -- sources: sys@v0.0.0-20210823070655-63515b42dcdf/LICENSE +- sources: sys@v0.0.0-20220520151302-bc2c85ada10a/LICENSE text: | Copyright (c) 2009 The Go Authors. All rights reserved. @@ -36,7 +36,7 @@ licenses: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- sources: sys@v0.0.0-20210823070655-63515b42dcdf/PATENTS +- sources: sys@v0.0.0-20220520151302-bc2c85ada10a/PATENTS text: | Additional IP Rights Grant (Patents) diff --git a/.licenses/go/golang.org/x/sys/unix.dep.yml b/.licenses/go/golang.org/x/sys/unix.dep.yml index b33445f4bcf..0b125d7ada7 100644 --- a/.licenses/go/golang.org/x/sys/unix.dep.yml +++ b/.licenses/go/golang.org/x/sys/unix.dep.yml @@ -1,12 +1,12 @@ --- name: golang.org/x/sys/unix -version: v0.0.0-20210823070655-63515b42dcdf +version: v0.0.0-20220520151302-bc2c85ada10a type: go summary: Package unix contains an interface to the low-level operating system primitives. homepage: https://pkg.go.dev/golang.org/x/sys/unix license: bsd-3-clause licenses: -- sources: sys@v0.0.0-20210823070655-63515b42dcdf/LICENSE +- sources: sys@v0.0.0-20220520151302-bc2c85ada10a/LICENSE text: | Copyright (c) 2009 The Go Authors. All rights reserved. @@ -35,7 +35,7 @@ licenses: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- sources: sys@v0.0.0-20210823070655-63515b42dcdf/PATENTS +- sources: sys@v0.0.0-20220520151302-bc2c85ada10a/PATENTS text: | Additional IP Rights Grant (Patents) From a929ff72aec475f13105590f677446af195dd1da Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2022 15:07:36 +0200 Subject: [PATCH 26/33] re-enable test for fixed bug --- internal/integrationtest/daemon/daemon_compile_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go index 18516115a5f..fce1420ad96 100644 --- a/internal/integrationtest/daemon/daemon_compile_test.go +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -30,8 +30,6 @@ func TestDaemonCompileOptions(t *testing.T) { // See: https://github.com/arduino/arduino-cli/issues/1614 // See: https://github.com/arduino/arduino-cli/pull/1820 - t.SkipNow() // TO BE Removed once the bug is fixed - env, cli := createEnvForDaemon(t) defer env.CleanUp() From 195390232c52a1438c7d37c2cc91d78f10264aff Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 3 Aug 2022 10:10:32 +0200 Subject: [PATCH 27/33] testsuite: disable postinstall Otherwise Windows CI will get stuck. --- internal/integrationtest/arduino-cli.go | 3 ++- internal/integrationtest/daemon/daemon_compile_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 937857171a0..0a3b62d361f 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -261,12 +261,13 @@ func (inst *ArduinoCLIInstance) BoardListWatch() (commands.ArduinoCoreService_Bo } // PlatformInstall calls the "PlatformInstall" gRPC method. -func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, arch, version string) (commands.ArduinoCoreService_PlatformInstallClient, error) { +func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, arch, version string, skipPostInst bool) (commands.ArduinoCoreService_PlatformInstallClient, error) { installCl, err := inst.cli.daemonClient.PlatformInstall(ctx, &commands.PlatformInstallRequest{ Instance: inst.instance, PlatformPackage: packager, Architecture: arch, Version: version, + SkipPostInstall: skipPostInst, }) logCallf(">>> PlatformInstall(%v:%v %v)\n", packager, arch, version) return installCl, err diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go index fce1420ad96..e3639b95ef7 100644 --- a/internal/integrationtest/daemon/daemon_compile_test.go +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -38,7 +38,7 @@ func TestDaemonCompileOptions(t *testing.T) { fmt.Printf("INIT> %v\n", ir.GetMessage()) })) - plInst, err := inst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5") + plInst, err := inst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5", true) require.NoError(t, err) for { msg, err := plInst.Recv() From 0896f4cef3c5bc821d0a23d99422767402b40808 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 5 Aug 2022 17:51:13 +0200 Subject: [PATCH 28/33] Removed useless startDaemon --- internal/integrationtest/daemon/daemon_board_watch_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/integrationtest/daemon/daemon_board_watch_test.go b/internal/integrationtest/daemon/daemon_board_watch_test.go index 4a76c6f084e..dce51bf5ff1 100644 --- a/internal/integrationtest/daemon/daemon_board_watch_test.go +++ b/internal/integrationtest/daemon/daemon_board_watch_test.go @@ -34,8 +34,6 @@ func TestArduinoCliDaemon(t *testing.T) { env, cli := createEnvForDaemon(t) defer env.CleanUp() - _ = cli.StartDaemon(false) - inst := cli.Create() require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { fmt.Printf("INIT> %v\n", ir.GetMessage()) From f21e86c80c785721203118cfa9f47ce59418eadf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 5 Aug 2022 17:51:48 +0200 Subject: [PATCH 29/33] Renamed inst -> grpcInst --- .../daemon/daemon_board_watch_test.go | 10 +++++----- .../integrationtest/daemon/daemon_compile_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/integrationtest/daemon/daemon_board_watch_test.go b/internal/integrationtest/daemon/daemon_board_watch_test.go index dce51bf5ff1..a526427b45d 100644 --- a/internal/integrationtest/daemon/daemon_board_watch_test.go +++ b/internal/integrationtest/daemon/daemon_board_watch_test.go @@ -34,24 +34,24 @@ func TestArduinoCliDaemon(t *testing.T) { env, cli := createEnvForDaemon(t) defer env.CleanUp() - inst := cli.Create() - require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + grpcInst := cli.Create() + require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { fmt.Printf("INIT> %v\n", ir.GetMessage()) })) // Run a one-shot board list - boardListResp, err := inst.BoardList(time.Second) + boardListResp, err := grpcInst.BoardList(time.Second) require.NoError(t, err) fmt.Printf("Got boardlist response with %d ports\n", len(boardListResp.GetPorts())) // Run a one-shot board list again (should not fail) - boardListResp, err = inst.BoardList(time.Second) + boardListResp, err = grpcInst.BoardList(time.Second) require.NoError(t, err) fmt.Printf("Got boardlist response with %d ports\n", len(boardListResp.GetPorts())) testWatcher := func() { // Run watcher - watcher, err := inst.BoardListWatch() + watcher, err := grpcInst.BoardListWatch() require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) go func() { diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go index e3639b95ef7..b3593178e8a 100644 --- a/internal/integrationtest/daemon/daemon_compile_test.go +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -33,12 +33,12 @@ func TestDaemonCompileOptions(t *testing.T) { env, cli := createEnvForDaemon(t) defer env.CleanUp() - inst := cli.Create() - require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + grpcInst := cli.Create() + require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { fmt.Printf("INIT> %v\n", ir.GetMessage()) })) - plInst, err := inst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5", true) + plInst, err := grpcInst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5", true) require.NoError(t, err) for { msg, err := plInst.Recv() @@ -56,13 +56,13 @@ func TestDaemonCompileOptions(t *testing.T) { require.NoError(t, err) // Re-init instance to update changes - require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) { + require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) { fmt.Printf("INIT> %v\n", ir.GetMessage()) })) // Build sketch (with errors) sk := paths.New("testdata", "bare_minimum") - compile, err := inst.Compile(context.Background(), "arduino:avr:uno:some_menu=bad", sk.String()) + compile, err := grpcInst.Compile(context.Background(), "arduino:avr:uno:some_menu=bad", sk.String()) require.NoError(t, err) for { msg, err := compile.Recv() @@ -83,7 +83,7 @@ func TestDaemonCompileOptions(t *testing.T) { } // Build sketch (without errors) - compile, err = inst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String()) + compile, err = grpcInst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String()) require.NoError(t, err) for { msg, err := compile.Recv() From d977ffe8ebfa962d75b6f54f3380fe6eb4eacb2c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 5 Aug 2022 17:56:51 +0200 Subject: [PATCH 30/33] Close daemon gRPC connection on test cleanup --- internal/integrationtest/arduino-cli.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 0a3b62d361f..f59967827cc 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -81,6 +81,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC // CleanUp closes the Arduino CLI client. func (cli *ArduinoCLI) CleanUp() { if cli.proc != nil { + cli.daemonConn.Close() cli.proc.Kill() cli.proc.Wait() } From 82e47d3c04e6d009e2914df56225587b64524653 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 5 Aug 2022 17:56:58 +0200 Subject: [PATCH 31/33] Added comment --- internal/integrationtest/daemon/daemon_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/integrationtest/daemon/daemon_test.go b/internal/integrationtest/daemon/daemon_test.go index 8d5e0f6886c..f43dbcccc22 100644 --- a/internal/integrationtest/daemon/daemon_test.go +++ b/internal/integrationtest/daemon/daemon_test.go @@ -24,6 +24,9 @@ import ( "go.bug.st/testsuite" ) +// createEnvForDaemon performs the minimum required operations to start the arduino-cli daemon. +// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests. +// The Environment must be disposed by calling the CleanUp method via defer. func createEnvForDaemon(t *testing.T) (*testsuite.Environment, *integrationtest.ArduinoCLI) { env := testsuite.NewEnvironment(t) From 87561febab2ccd8481aa761aae3cc2f95bcaec72 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 8 Aug 2022 19:22:00 +0200 Subject: [PATCH 32/33] Apply suggestions from code review Co-authored-by: per1234 --- Taskfile.yml | 2 +- internal/integrationtest/arduino-cli.go | 10 +--------- internal/integrationtest/core/core_test.go | 4 +--- internal/integrationtest/daemon/daemon_compile_test.go | 6 ------ 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index d3fd8b71b28..e62e419ab4a 100755 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -90,7 +90,7 @@ tasks: # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml go:test: - desc: Run unit tests and part of the integration tests + desc: Run unit tests and the Go-based integration tests deps: - task: go:build dir: '{{default "./" .GO_MODULE_PATH}}' diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index f59967827cc..756ef610c4c 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -61,7 +61,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC cli := &ArduinoCLI{ path: config.ArduinoCLIPath, t: require.New(env.T()), - dataDir: env.RootDir().Join("arduino15"), + dataDir: env.RootDir().Join("Arduino15"), sketchbookDir: env.RootDir().Join("Arduino"), stagingDir: env.RootDir().Join("arduino15/staging"), } @@ -153,14 +153,6 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string { cli.t.NoError(cliProc.Start()) cli.proc = cliProc - - // var daemonAddr struct { - // IP string - // Port string - // } - // dec := json.NewDecoder(stdout) - // cli.t.NoError(dec.Decode(&daemonAddr)) - // cli.daemonAddr = daemonAddr.IP + ":" + daemonAddr.Port cli.daemonAddr = "127.0.0.1:50051" copy := func(dst io.Writer, src io.Reader) { diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index ee55c688597..090793b7bdd 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -62,7 +62,6 @@ func TestCoreSearch(t *testing.T) { out, _, err = cli.Run("core", "search", "test_core", "--all", "--format", "json", "--additional-urls="+url.String()) require.NoError(t, err) requirejson.Len(t, out, 2) - // requirejson.Len(t, out, 3) // Test failure checkPlatformIsInJSONOutput := func(stdout []byte, id, version string) { jqquery := fmt.Sprintf(`[{id:"%s", latest:"%s"}]`, id, version) @@ -74,7 +73,6 @@ func TestCoreSearch(t *testing.T) { require.NoError(t, err) checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5") checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6") - //checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.9") // Test failure // Search using Retrokit Package Maintainer out, _, err = cli.Run("core", "search", "Retrokits-RK002", "--all", "--additional-urls="+url.String(), "--format", "json") @@ -93,7 +91,6 @@ func TestCoreSearch(t *testing.T) { require.NoError(t, err) checkPlatformIsInJSONOutput(out, "Package:x86", "1.2.3") - // Check search with case, accents and spaces runSearch := func(searchArgs string, expectedIDs ...string) { args := []string{"core", "search", "--format", "json"} args = append(args, strings.Split(searchArgs, " ")...) @@ -106,6 +103,7 @@ func TestCoreSearch(t *testing.T) { } } + // Check search with case, accents and spaces runSearch("mkr1000", "arduino:samd") runSearch("mkr 1000", "arduino:samd") diff --git a/internal/integrationtest/daemon/daemon_compile_test.go b/internal/integrationtest/daemon/daemon_compile_test.go index b3593178e8a..2995c15afc8 100644 --- a/internal/integrationtest/daemon/daemon_compile_test.go +++ b/internal/integrationtest/daemon/daemon_compile_test.go @@ -74,9 +74,6 @@ func TestDaemonCompileOptions(t *testing.T) { fmt.Println("COMPILE ERROR>", err) break } - // if msg.OutStream != nil { - // fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream())) - // } if msg.ErrStream != nil { fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) } @@ -91,9 +88,6 @@ func TestDaemonCompileOptions(t *testing.T) { break } require.NoError(t, err) - // if msg.OutStream != nil { - // fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream())) - // } if msg.ErrStream != nil { fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) } From 757fa06991a91a34419d995db151f2d2c525d1ed Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 9 Aug 2022 10:25:56 +0200 Subject: [PATCH 33/33] Update internal/integrationtest/arduino-cli.go Co-authored-by: per1234 --- internal/integrationtest/arduino-cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 756ef610c4c..e1ad8f29487 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -63,7 +63,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC t: require.New(env.T()), dataDir: env.RootDir().Join("Arduino15"), sketchbookDir: env.RootDir().Join("Arduino"), - stagingDir: env.RootDir().Join("arduino15/staging"), + stagingDir: env.RootDir().Join("Arduino15/staging"), } if config.UseSharedStagingFolder { cli.stagingDir = env.SharedDownloadsDir()