Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions framework/ldtest/test_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"sync"

"github.com/launchdarkly/sdk-test-harness/v2/framework"
"github.com/launchdarkly/sdk-test-harness/v2/framework/helpers"
Expand Down Expand Up @@ -44,6 +45,51 @@ type MultiTestLogger struct {
Loggers []TestLogger
}

type CountingTestLogger struct {
wrapped TestLogger
totalTests int
skippedTests int
mu sync.Mutex
}

func NewCountingTestLogger(wrapped TestLogger) *CountingTestLogger {
return &CountingTestLogger{
wrapped: wrapped,
}
}

func (c *CountingTestLogger) TestStarted(id TestID) {
c.mu.Lock()
c.totalTests++
c.mu.Unlock()
c.wrapped.TestStarted(id)
}

func (c *CountingTestLogger) TestError(id TestID, err error) {
c.wrapped.TestError(id, err)
}

func (c *CountingTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput) {
c.wrapped.TestFinished(id, result, debugOutput)
}

func (c *CountingTestLogger) TestSkipped(id TestID, reason string) {
c.mu.Lock()
c.skippedTests++
c.mu.Unlock()
c.wrapped.TestSkipped(id, reason)
}

func (c *CountingTestLogger) EndLog(results Results) error {
return c.wrapped.EndLog(results)
}

func (c *CountingTestLogger) GetCounts() (total, skipped int) {
c.mu.Lock()
defer c.mu.Unlock()
return c.totalTests, c.skippedTests
}

func (c ConsoleTestLogger) TestStarted(id TestID) {
fmt.Printf("[%s]\n", id)
}
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ func run(params commandParams) (*ldtest.Results, error) {
}}
}

results := sdktests.RunSDKTestSuite(harness, params.filters, testLogger)
countingLogger := ldtest.NewCountingTestLogger(testLogger)
testLogger = countingLogger

results := sdktests.RunSDKTestSuite(harness, params.filters, countingLogger)

fmt.Println()
logErr := testLogger.EndLog(results)

total, skipped := countingLogger.GetCounts()
fmt.Printf("Test Summary: %d total, %d skipped, %d ran\n", total, skipped, total-skipped)
fmt.Println()

if params.stopServiceAtEnd {
fmt.Println("Stopping test service")
if err := harness.StopService(); err != nil {
Expand Down
Loading