Skip to content

Commit

Permalink
Cherry-pick #20127 to 7.x: Fix failing unit tests on windows (#20181)
Browse files Browse the repository at this point in the history
* [Ingest Manager] Fix failing unit tests on windows (#20127)

* remove skip

* close properly

* changelog

* space

* Changelog

* prevent closing closed

* changelog
  • Loading branch information
michalpristas authored Jul 23, 2020
1 parent cd7e7d7 commit 85d07ae
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
- Remove support for logs type and use logfile {pull}19761[19761]
- Avoid comparing uncomparable types on enroll {issue}19976[19976]
- Fix issues with merging of elastic-agent.yml and fleet.yml {pull}20026[20026]
- Fix failing unit tests on windows {pull}20127[20127]
- Prevent closing closed reader {pull}20214[20214]
- Improve GRPC stop to be more relaxed {pull}20118[20118]

==== New features
Expand Down
1 change: 1 addition & 0 deletions x-pack/elastic-agent/pkg/agent/application/action_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newActionStore(log *logger.Logger, store storeLoad) (*actionStore, error) {
if err != nil {
return &actionStore{log: log, store: store}, nil
}
defer reader.Close()

var action actionConfigChangeSerializer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -20,10 +19,6 @@ import (
)

func TestActionStore(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on windows see https://github.com/elastic/beats/issues/19919")
}

log, _ := logger.New("action_store")
withFile := func(fn func(t *testing.T, file string)) func(*testing.T) {
return func(t *testing.T) {
Expand Down
8 changes: 0 additions & 8 deletions x-pack/elastic-agent/pkg/agent/application/info/agent_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ func getInfoFromStore(s ioStore) (*persistentAgentInfo, error) {
errors.M(errors.MetaKeyPath, agentConfigFile))
}

if err := reader.Close(); err != nil {
return nil, err
}

configMap, err := cfg.ToMapStr()
if err != nil {
return nil, errors.New(err,
Expand Down Expand Up @@ -137,10 +133,6 @@ func updateAgentInfo(s ioStore, agentInfo *persistentAgentInfo) error {
errors.M(errors.MetaKeyPath, agentConfigFile))
}

if err := reader.Close(); err != nil {
return err
}

configMap := make(map[string]interface{})
if err := cfg.Unpack(&configMap); err != nil {
return errors.New(err, "failed to unpack stored config to map")
Expand Down
4 changes: 4 additions & 0 deletions x-pack/elastic-agent/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func NewConfigFrom(from interface{}) (*Config, error) {
}

if in, ok := from.(io.Reader); ok {
if closer, ok := from.(io.Closer); ok {
defer closer.Close()
}

content, err := ioutil.ReadAll(in)
if err != nil {
return nil, err
Expand Down

0 comments on commit 85d07ae

Please sign in to comment.