diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 318c7d4..b8b07f0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/pkg/events/Produce.go b/pkg/events/Produce.go index 25196d5..c803482 100644 --- a/pkg/events/Produce.go +++ b/pkg/events/Produce.go @@ -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) diff --git a/tests/expense_test.go b/tests/expense_test.go index 0c7affa..c142e88 100644 --- a/tests/expense_test.go +++ b/tests/expense_test.go @@ -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) + } + }) } }