Skip to content

Commit

Permalink
final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed Mar 29, 2024
1 parent 920e27f commit 4396af8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: docker-compose up -d
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: ./go.mod
- name: Run tests
run: make test
- name: Compose down
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/Produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c KafkaClient) Producer(ctx context.Context, record *kgo.Record) error {
results := c.Client.ProduceSync(ctx, record)
for _, pr := range results {
if pr.Err != nil {
return fmt.Errorf("Error sending synchronous message: %v \n", pr.Err)
return fmt.Errorf("error sending synchronous message: %v", pr.Err)
} else {
fmt.Printf("Message sent: topic: %s, offset: %d, partition: %d \n",
pr.Record.Topic, pr.Record.Offset, pr.Record.Partition)
Expand Down
54 changes: 34 additions & 20 deletions tests/expense_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,43 @@ import (
)

func TestExpenseAPI(t *testing.T) {
expense := gen.Expense{
ExpenseID: "test",
UserID: "10010",
Category: "kafka",
Amount: 20.5,
Currency: "AUD",
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
Description: nil,
Receipt: nil,
testCases := []struct {
name string
expense gen.Expense
expected int
}{
{
name: "Test Expense API",
expense: gen.Expense{
ExpenseID: "test",
UserID: "10010",
Category: "kafka",
Amount: 20.5,
Currency: "AUD",
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
Description: nil,
Receipt: nil,
},
expected: http.StatusOK,
},
}

jsonData, err := json.Marshal(expense)
if err != nil {
t.Fatalf("Error marshalling json: %v", err)
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
jsonData, err := json.Marshal(tc.expense)
if err != nil {
t.Fatalf("Error marshalling json: %v", err)
}

resp, err := http.Post("http://localhost:8083/api/expense", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
t.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
resp, err := http.Post("http://localhost:8083/api/expense", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
t.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
t.Fatalf("Expected status OK, got %v", resp.StatusCode)
if resp.StatusCode != tc.expected {
t.Fatalf("Expected status %v, got %v", tc.expected, resp.StatusCode)
}
})
}
}

0 comments on commit 4396af8

Please sign in to comment.