Skip to content

Commit

Permalink
feat: add ResponseHeaderAssertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-gang committed Sep 26, 2024
1 parent 336dcfa commit 5b869b4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/assertions/response_header_assertion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package assertions

import (
"fmt"

kafkaapi "github.com/codecrafters-io/kafka-tester/protocol/api"
"github.com/codecrafters-io/tester-utils/logger"
)

type ResponseHeaderAssertion struct {
ActualValue kafkaapi.ResponseHeader
ExpectedValue kafkaapi.ResponseHeader
}

func NewResponseHeaderAssertion(actualValue kafkaapi.ResponseHeader, expectedValue kafkaapi.ResponseHeader) ResponseHeaderAssertion {
return ResponseHeaderAssertion{ActualValue: actualValue, ExpectedValue: expectedValue}
}

func (a ResponseHeaderAssertion) Evaluate(fields []string, logger *logger.Logger) error {
if Contains(fields, "CorrelationId") {
if a.ActualValue.CorrelationId != a.ExpectedValue.CorrelationId {
return fmt.Errorf("Expected %s to be %d, got %d", "CorrelationId", a.ExpectedValue.CorrelationId, a.ActualValue.CorrelationId)
}
logger.Successf("✓ Correlation ID: %v", a.ActualValue.CorrelationId)
}
return nil
}

0 comments on commit 5b869b4

Please sign in to comment.