Skip to content

Commit 91f7240

Browse files
committed
Add tests
1 parent e176a59 commit 91f7240

File tree

6 files changed

+773
-9
lines changed

6 files changed

+773
-9
lines changed

.licenses/pluggable-discovery-protocol-handler/go/github.com/arduino/go-paths-helper.dep.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
name: github.com/arduino/go-paths-helper
3-
version: v1.0.1
3+
version: v1.6.1
44
type: go
5-
summary:
5+
summary:
66
homepage: https://pkg.go.dev/github.com/arduino/go-paths-helper
77
license: gpl-2.0-or-later
88
licenses:

.licenses/pluggable-discovery-protocol-handler/go/github.com/arduino/go-properties-orderedmap.dep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: github.com/arduino/go-properties-orderedmap
3-
version: v1.4.0
3+
version: v1.6.0
44
type: go
55
summary: Package properties is a library for handling maps of hierarchical properties.
66
homepage: https://pkg.go.dev/github.com/arduino/go-properties-orderedmap
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: github.com/pkg/errors
3+
version: v0.9.1
4+
type: go
5+
summary: Package errors provides simple error handling primitives.
6+
homepage: https://pkg.go.dev/github.com/pkg/errors
7+
license: bsd-2-clause
8+
licenses:
9+
- sources: LICENSE
10+
text: |
11+
Copyright (c) 2015, Dave Cheney <[email protected]>
12+
All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are met:
16+
17+
* Redistributions of source code must retain the above copyright notice, this
18+
list of conditions and the following disclaimer.
19+
20+
* Redistributions in binary form must reproduce the above copyright notice,
21+
this list of conditions and the following disclaimer in the documentation
22+
and/or other materials provided with the distribution.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
- sources: README.md
35+
text: BSD-2-Clause
36+
notices: []

discovery_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// This file is part of dummy-discovery.
3+
//
4+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
5+
//
6+
// This software is released under the GNU General Public License version 3,
7+
// which covers the main part of arduino-cli.
8+
// The terms of this license can be found at:
9+
// https://www.gnu.org/licenses/gpl-3.0.en.html
10+
//
11+
// You can be released from the requirements of the above licenses by purchasing
12+
// a commercial license. Buying such a license is mandatory if you want to modify or
13+
// otherwise use the software for commercial activities involving the Arduino
14+
// software without disclosing the source code of your own applications. To purchase
15+
// a commercial license, send an email to [email protected].
16+
//
17+
18+
package discovery
19+
20+
import (
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/executils"
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
func runDummyDiscovery(t *testing.T) *executils.Process {
28+
discoveryDir := "dummy-discovery"
29+
// Build dummy-discovery for testing
30+
builder, err := executils.NewProcess("go", "build")
31+
require.NoError(t, err)
32+
builder.SetDir(discoveryDir)
33+
require.NoError(t, builder.Run())
34+
discovery, err := executils.NewProcess("./dummy-discovery")
35+
require.NoError(t, err)
36+
discovery.SetDir(discoveryDir)
37+
return discovery
38+
}
39+
40+
func TestDiscoveryStdioHandling(t *testing.T) {
41+
discovery := runDummyDiscovery(t)
42+
43+
stdout, err := discovery.StdoutPipe()
44+
require.NoError(t, err)
45+
stdin, err := discovery.StdinPipe()
46+
require.NoError(t, err)
47+
48+
require.NoError(t, discovery.Start())
49+
defer discovery.Kill()
50+
51+
n, err := stdin.Write([]byte("quit\n"))
52+
require.Greater(t, n, 0)
53+
require.NoError(t, err)
54+
output := [1024]byte{}
55+
// require.NoError(t, discovery.Wait())
56+
n, err = stdout.Read(output[:])
57+
require.Greater(t, n, 0)
58+
require.NoError(t, err)
59+
60+
expectedOutput := "{\n \"eventType\": \"quit\",\n \"message\": \"OK\"\n}\n"
61+
require.Equal(t, expectedOutput, string(output[:n]))
62+
}

go.mod

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module github.com/arduino/pluggable-discovery-protocol-handler/v2
22

33
go 1.16
44

5-
require github.com/arduino/go-properties-orderedmap v1.4.0
5+
require (
6+
github.com/arduino/arduino-cli v0.0.0-20211123110800-c756a0f1305d
7+
github.com/arduino/go-properties-orderedmap v1.6.0
8+
github.com/stretchr/testify v1.7.0
9+
)

0 commit comments

Comments
 (0)