Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
- switched to configuration layout mandated by v2
- added `mage test` target that will run both unit and integration
  tests
- switched CI runs from just running unit tests to running all tests
- Skipped integration tests that require docker to run logstash or
  kafka, support for doing that is finalized in magefile.
- updated example config file

Closes elastic#244
  • Loading branch information
leehinman committed Feb 24, 2023
1 parent cdf8aa3 commit 4923b26
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pipeline {
withGithubNotify(context: "Test-${PLATFORM}") {
dir("${BASE_DIR}"){
withMageEnv(){
cmd(label: 'Go unitTest', script: 'mage unitTest')
cmd(label: 'Go unitTest', script: 'mage test')
}
}
}
Expand Down
32 changes: 13 additions & 19 deletions controller/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ package controller

import (
"context"
"errors"
"io/fs"
"net"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand All @@ -21,16 +24,12 @@ import (

func TestUnmanaged(t *testing.T) {
_ = logp.DevelopmentSetup()
serverAddr := filepath.Join(os.TempDir(), "test-unmanaged-shipper.sock")
serverAddr := filepath.Join(t.TempDir(), "test.sock")
cfg := config.DefaultConfig()
cfg.Type = "console"
cfg.Shipper.Output.Console = &output.ConsoleConfig{Enabled: true}
cfg.Shipper.Server.Server = serverAddr

defer func() {
_ = os.Remove(serverAddr)
}()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)

go func() {
Expand All @@ -45,21 +44,16 @@ func TestUnmanaged(t *testing.T) {
default:
}
_, err := os.Stat(serverAddr)
if !os.IsNotExist(err) {
break
if err != nil && errors.Is(err, fs.ErrNotExist) {
continue
}
con, err := net.Dial("unix", serverAddr)
if err != nil && strings.Contains(err.Error(), "connection refused") {
continue
}
require.NoError(t, err)
t.Cleanup(func() { _ = con.Close() })
break
}
// remove the file now that we know it's there
defer func() {
_ = os.Remove(serverAddr)
}()

// basic test, make sure output is running
con, err := net.Dial("unix", serverAddr)
require.NoError(t, err)
defer func() {
_ = con.Close()
}()

cancel()
}
Loading

0 comments on commit 4923b26

Please sign in to comment.