Skip to content

Commit

Permalink
On conn err, do not wrap as regular err (#66)
Browse files Browse the repository at this point in the history
* On conn err, do not wrap as regular err

* Use wrappedErr
  • Loading branch information
jonhenrik13 authored Sep 2, 2024
1 parent e06b39b commit d52fb5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/configuration/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"

"go.qbee.io/agent/app/api"
"go.qbee.io/agent/app/log"
)

Expand Down Expand Up @@ -58,7 +60,12 @@ func (srv *Service) getFileMetadataFromAPI(ctx context.Context, src string) (*Fi
fileMetadataResp := new(fileMetadataResponse)

if err := srv.api.Get(ctx, path, fileMetadataResp); err != nil {
return nil, fmt.Errorf("error getting file metadata: %w", err)
wrappedErr := fmt.Errorf("error getting file metadata: %w", err)
if errors.As(err, new(api.ConnectionError)) {
return nil, api.NewConnectionError(wrappedErr)
}

return nil, wrappedErr
}

return &fileMetadataResp.Data, nil
Expand Down
30 changes: 30 additions & 0 deletions app/configuration/bundle_file_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"testing"

"go.qbee.io/agent/app/agent"
"go.qbee.io/agent/app/configuration"
"go.qbee.io/agent/app/utils/assert"
"go.qbee.io/agent/app/utils/runner"
Expand Down Expand Up @@ -380,3 +381,32 @@ func Test_FileDistributionBundle_Destination_Is_Empty(t *testing.T) {

assert.Empty(t, reports)
}

func Test_FileDistirbution_No_Reports_Connectivity_Issues(t *testing.T) {
r := runner.New(t)

r.CreateJSON("/etc/qbee/qbee-agent.json", agent.Config{
DeviceHubServer: "some-non-existing-host",
DeviceHubPort: "8888",
})

agentConfig := configuration.CommittedConfig{
Bundles: []string{configuration.BundleFileDistribution},
BundleData: configuration.BundleData{
FileDistribution: &configuration.FileDistributionBundle{
Metadata: configuration.Metadata{Enabled: true},
FileSets: []configuration.FileSet{
{
Files: []configuration.File{
{Source: "/non-existing-file", Destination: "/tmp/test1"},
},
},
},
},
},
}

reports, _ := configuration.ExecuteTestConfigInDocker(r, agentConfig)

assert.Empty(t, reports)
}

0 comments on commit d52fb5e

Please sign in to comment.