Skip to content

Commit

Permalink
Updated integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jan 22, 2025
1 parent 4f73e4c commit fc6d0a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 14 additions & 3 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,21 @@ func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig)
// 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) (*Environment, *ArduinoCLI) {
return CreateEnvForDaemonWithUserAgent(t, "cli-test/0.0.0")
}

// CreateEnvForDaemonWithUserAgent 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 CreateEnvForDaemonWithUserAgent(t *testing.T, userAgent string) (*Environment, *ArduinoCLI) {
env := NewEnvironment(t)

cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{
ArduinoCLIPath: FindRepositoryRootPath(t).Join("arduino-cli"),
UseSharedStagingFolder: true,
})

_ = cli.StartDaemon(false)
_ = cli.StartDaemon(false, userAgent)
return env, cli
}

Expand Down Expand Up @@ -410,7 +417,7 @@ func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader
}

// StartDaemon starts the Arduino CLI daemon. It returns the address of the daemon.
func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
func (cli *ArduinoCLI) StartDaemon(verbose bool, userAgent string) string {
args := []string{"daemon", "--json"}
if cli.cliConfigPath != nil {
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
Expand Down Expand Up @@ -450,7 +457,11 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
for retries := 5; retries > 0; retries-- {
time.Sleep(time.Second)

conn, err := grpc.NewClient(cli.daemonAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(
cli.daemonAddr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUserAgent(userAgent),
)
if err != nil {
connErr = err
continue
Expand Down
5 changes: 4 additions & 1 deletion internal/integrationtest/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func (env *Environment) HTTPServeFile(port uint16, path *paths.Path, isDaemon bo
http.ServeFile(w, r, path.String())
if isDaemon {
// Test that the user-agent contains metadata from the context when the CLI is in daemon mode
require.Contains(t, r.Header.Get("User-Agent"), "arduino-cli/git-snapshot grpc-go")
userAgent := r.Header.Get("User-Agent")
require.Contains(t, userAgent, "arduino-cli/git-snapshot")
require.Contains(t, userAgent, "cli-test/0.0.0")
require.Contains(t, userAgent, "grpc-go")
}
})
server := &http.Server{
Expand Down

0 comments on commit fc6d0a6

Please sign in to comment.