Skip to content

Commit 48c5388

Browse files
author
agilira
committed
Improved test coverage for new functions
1 parent 4492269 commit 48c5388

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ jobs:
3535
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
3636
go tool cover -func=coverage.out
3737
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v4
40+
with:
41+
file: ./coverage.out
42+
fail_ci_if_error: false
43+
verbose: true
44+
continue-on-error: true
3845

3946

4047
quality:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Built for Styx, it includes error codes, stack traces, user messages, and JSON s
77
[![CI](https://github.com/agilira/go-errors/actions/workflows/ci.yml/badge.svg)](https://github.com/agilira/go-errors/actions/workflows/ci.yml)
88
[![Security](https://img.shields.io/badge/Security-gosec-brightgreen)](https://github.com/agilira/go-errors/actions/workflows/ci.yml)
99
[![Go Report Card](https://goreportcard.com/badge/github.com/agilira/go-errors)](https://goreportcard.com/report/github.com/agilira/go-errors)
10-
[![Coverage](https://img.shields.io/badge/coverage-86%25-brightgreen)](https://github.com/agilira/go-errors/actions/workflows/ci.yml)
10+
[![Coverage](https://codecov.io/gh/agilira/go-errors/branch/main/graph/badge.svg)](https://codecov.io/gh/agilira/go-errors)
1111

1212
## Features
1313
- Structured error type: code, message, context, cause, severity

coverage

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
mode: set
2+
github.com/agilira/go-errors/errors.go:35.49,43.2 1 1
3+
github.com/agilira/go-errors/errors.go:47.72,57.2 1 1
4+
github.com/agilira/go-errors/errors.go:61.92,69.2 1 1
5+
github.com/agilira/go-errors/helpers.go:17.61,27.2 1 1
6+
github.com/agilira/go-errors/helpers.go:31.32,33.2 1 1
7+
github.com/agilira/go-errors/helpers.go:36.32,38.2 1 1
8+
github.com/agilira/go-errors/helpers.go:42.33,43.6 1 1
9+
github.com/agilira/go-errors/helpers.go:43.6,45.23 2 1
10+
github.com/agilira/go-errors/helpers.go:45.23,47.4 1 1
11+
github.com/agilira/go-errors/helpers.go:48.3,48.18 1 1
12+
github.com/agilira/go-errors/helpers.go:54.46,55.17 1 1
13+
github.com/agilira/go-errors/helpers.go:55.17,56.52 1 1
14+
github.com/agilira/go-errors/helpers.go:56.52,58.4 1 1
15+
github.com/agilira/go-errors/helpers.go:59.3,59.27 1 1
16+
github.com/agilira/go-errors/helpers.go:61.2,61.14 1 1
17+
github.com/agilira/go-errors/helpers.go:66.39,67.19 1 1
18+
github.com/agilira/go-errors/helpers.go:67.19,69.3 1 1
19+
github.com/agilira/go-errors/helpers.go:70.2,70.35 1 1
20+
github.com/agilira/go-errors/helpers.go:70.35,72.3 1 1
21+
github.com/agilira/go-errors/helpers.go:73.2,73.14 1 1
22+
github.com/agilira/go-errors/helpers.go:79.45,81.2 1 1
23+
github.com/agilira/go-errors/json.go:15.47,22.24 2 1
24+
github.com/agilira/go-errors/json.go:22.24,23.22 1 1
25+
github.com/agilira/go-errors/json.go:23.22,25.5 1 1
26+
github.com/agilira/go-errors/json.go:26.4,26.13 1 1
27+
github.com/agilira/go-errors/stacktrace.go:23.46,28.2 4 1
28+
github.com/agilira/go-errors/stacktrace.go:32.38,33.36 1 1
29+
github.com/agilira/go-errors/stacktrace.go:33.36,35.3 1 1
30+
github.com/agilira/go-errors/stacktrace.go:36.2,38.6 3 1
31+
github.com/agilira/go-errors/stacktrace.go:38.6,46.12 8 1
32+
github.com/agilira/go-errors/stacktrace.go:46.12,47.9 1 1
33+
github.com/agilira/go-errors/stacktrace.go:50.2,50.19 1 1
34+
github.com/agilira/go-errors/usermsg.go:11.52,14.2 2 1
35+
github.com/agilira/go-errors/usermsg.go:18.67,19.22 1 1
36+
github.com/agilira/go-errors/usermsg.go:19.22,21.3 1 1
37+
github.com/agilira/go-errors/usermsg.go:22.2,23.10 2 1
38+
github.com/agilira/go-errors/usermsg.go:28.38,31.2 2 1
39+
github.com/agilira/go-errors/usermsg.go:35.54,38.2 2 1
40+
github.com/agilira/go-errors/usermsg.go:42.38,43.21 1 1
41+
github.com/agilira/go-errors/usermsg.go:43.21,45.3 1 1
42+
github.com/agilira/go-errors/usermsg.go:46.2,46.18 1 1
43+
github.com/agilira/go-errors/usermsg.go:51.39,53.2 1 1
44+
github.com/agilira/go-errors/usermsg.go:57.36,59.2 1 1

errors_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,87 @@ func TestUserMessageWithEmptyBoth(t *testing.T) {
265265
t.Errorf("Expected empty string when both messages are empty, got: %s", result)
266266
}
267267
}
268+
269+
func TestWithContext(t *testing.T) {
270+
err := New(TestCodeValidation, "Test error")
271+
272+
// Test adding context to error with nil context
273+
err.Context = nil
274+
err = err.WithContext("key1", "value1")
275+
if err.Context == nil {
276+
t.Error("Expected context to be initialized")
277+
}
278+
if err.Context["key1"] != "value1" {
279+
t.Errorf("Expected context key1 to be 'value1', got '%v'", err.Context["key1"])
280+
}
281+
282+
// Test adding more context
283+
err = err.WithContext("key2", "value2")
284+
if err.Context["key2"] != "value2" {
285+
t.Errorf("Expected context key2 to be 'value2', got '%v'", err.Context["key2"])
286+
}
287+
288+
// Test updating existing context
289+
err = err.WithContext("key1", "updated_value")
290+
if err.Context["key1"] != "updated_value" {
291+
t.Errorf("Expected context key1 to be 'updated_value', got '%v'", err.Context["key1"])
292+
}
293+
}
294+
295+
func TestAsRetryable(t *testing.T) {
296+
err := New(TestCodeValidation, "Test error")
297+
298+
// Test marking error as retryable
299+
err = err.AsRetryable()
300+
if !err.Retryable {
301+
t.Error("Expected error to be marked as retryable")
302+
}
303+
304+
// Test that it returns the same error instance for chaining
305+
if err.AsRetryable() != err {
306+
t.Error("Expected AsRetryable to return the same error instance")
307+
}
308+
}
309+
310+
func TestWithSeverity(t *testing.T) {
311+
err := New(TestCodeValidation, "Test error")
312+
313+
// Test setting severity
314+
err = err.WithSeverity("warning")
315+
if err.Severity != "warning" {
316+
t.Errorf("Expected severity to be 'warning', got '%s'", err.Severity)
317+
}
318+
319+
// Test setting different severity
320+
err = err.WithSeverity("critical")
321+
if err.Severity != "critical" {
322+
t.Errorf("Expected severity to be 'critical', got '%s'", err.Severity)
323+
}
324+
325+
// Test that it returns the same error instance for chaining
326+
if err.WithSeverity("info") != err {
327+
t.Error("Expected WithSeverity to return the same error instance")
328+
}
329+
}
330+
331+
func TestMethodChaining(t *testing.T) {
332+
err := New(TestCodeValidation, "Test error").
333+
WithUserMessage("User message").
334+
WithContext("key", "value").
335+
WithSeverity("warning").
336+
AsRetryable()
337+
338+
// Verify all methods were applied
339+
if err.UserMsg != "User message" {
340+
t.Error("Expected user message to be set")
341+
}
342+
if err.Context["key"] != "value" {
343+
t.Error("Expected context to be set")
344+
}
345+
if err.Severity != "warning" {
346+
t.Error("Expected severity to be set")
347+
}
348+
if !err.Retryable {
349+
t.Error("Expected error to be retryable")
350+
}
351+
}

0 commit comments

Comments
 (0)