Skip to content

Commit aed7a94

Browse files
wip
1 parent 429f525 commit aed7a94

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package result_test
17+
18+
import (
19+
"reflect"
20+
"strings"
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
24+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
25+
"github.com/stretchr/testify/require"
26+
)
27+
28+
func getStructJsonTags(a any) []string {
29+
tags := []string{}
30+
rt := reflect.TypeOf(a)
31+
if rt.Kind() != reflect.Struct {
32+
rt = rt.Elem()
33+
if rt.Kind() != reflect.Struct {
34+
panic("must be a struct")
35+
}
36+
}
37+
for i := 0; i < rt.NumField(); i++ {
38+
tag := rt.Field(i).Tag.Get("json")
39+
if tag == "" {
40+
continue
41+
}
42+
key, _, _ := strings.Cut(tag, ",")
43+
tags = append(tags, key)
44+
}
45+
return tags
46+
}
47+
48+
func mustContainsAllPropertyOfRpcStruct(t *testing.T, a, b any) {
49+
require.EqualValues(t, getStructJsonTags(a), getStructJsonTags(b))
50+
}
51+
52+
func TestAllFieldAreMapped(t *testing.T) {
53+
platformRelease := &rpc.PlatformRelease{}
54+
platformReleaseResult := result.NewPlatformRelease(platformRelease)
55+
mustContainsAllPropertyOfRpcStruct(t, platformRelease, platformReleaseResult)
56+
57+
libraryRpc := &rpc.Library{}
58+
libraryResult := result.NewLibrary(libraryRpc)
59+
mustContainsAllPropertyOfRpcStruct(t, libraryRpc, libraryResult)
60+
61+
libraryReleaseRpc := &rpc.LibraryRelease{}
62+
libraryReleaseResult := result.NewLibraryRelease(libraryReleaseRpc)
63+
mustContainsAllPropertyOfRpcStruct(t, libraryReleaseRpc, libraryReleaseResult)
64+
65+
installedLibrary := &rpc.InstalledLibrary{}
66+
installedLibraryResult := result.NewInstalledLibrary(installedLibrary)
67+
mustContainsAllPropertyOfRpcStruct(t, installedLibrary, installedLibraryResult)
68+
69+
downloadResource := &rpc.DownloadResource{}
70+
downloadResourceResult := result.NewDownloadResource(downloadResource)
71+
mustContainsAllPropertyOfRpcStruct(t, downloadResource, downloadResourceResult)
72+
73+
libraryDependencyRpc := &rpc.LibraryDependency{}
74+
libraryDependencyResult := result.NewLibraryDependency(libraryDependencyRpc)
75+
mustContainsAllPropertyOfRpcStruct(t, libraryDependencyRpc, libraryDependencyResult)
76+
77+
portRpc := &rpc.Port{}
78+
portResult := result.NewPort(portRpc)
79+
mustContainsAllPropertyOfRpcStruct(t, portRpc, portResult)
80+
81+
boardDetailsResponseRpc := &rpc.BoardDetailsResponse{}
82+
boardDetailsResponseResult := result.NewBoardDetailsResponse(boardDetailsResponseRpc)
83+
mustContainsAllPropertyOfRpcStruct(t, boardDetailsResponseRpc, boardDetailsResponseResult)
84+
85+
packageRpc := &rpc.Package{}
86+
packageResult := result.NewPackage(packageRpc)
87+
mustContainsAllPropertyOfRpcStruct(t, packageRpc, packageResult)
88+
89+
helpRpc := &rpc.Help{}
90+
helpResult := result.NewHelp(helpRpc)
91+
mustContainsAllPropertyOfRpcStruct(t, helpRpc, helpResult)
92+
93+
boardPlatformRpc := &rpc.BoardPlatform{}
94+
boardPlatformResult := result.NewBoardPlatform(boardPlatformRpc)
95+
mustContainsAllPropertyOfRpcStruct(t, boardPlatformRpc, boardPlatformResult)
96+
97+
// TODO continue from line 446
98+
}

0 commit comments

Comments
 (0)