MCPcopy Create free account
hub / github.com/github/gh-aw / TestValidationError

Function TestValidationError

pkg/workflow/error_helpers_test.go:14–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestValidationError(t *testing.T) {
15 t.Run("basic validation error", func(t *testing.T) {
16 err := NewValidationError("title", "", "cannot be empty", "Provide a non-empty title")
17
18 require.Error(t, err)
19 assert.Contains(t, err.Error(), "Validation failed for field 'title'")
20 assert.Contains(t, err.Error(), "Reason: cannot be empty")
21 assert.Contains(t, err.Error(), "Suggestion: Provide a non-empty title")
22
23 // Check timestamp is included
24 assert.Contains(t, err.Error(), "[")
25 assert.Contains(t, err.Error(), "T")
26 })
27
28 t.Run("validation error with long value", func(t *testing.T) {
29 longValue := strings.Repeat("a", 200)
30 err := NewValidationError("body", longValue, "too long", "Shorten the body")
31
32 require.Error(t, err)
33 // Value should be truncated
34 assert.Contains(t, err.Error(), "...")
35 assert.Less(t, len(err.Error()), len(longValue)+200)
36 })
37
38 t.Run("validation error without suggestion", func(t *testing.T) {
39 err := NewValidationError("labels", "invalid", "not allowed", "")
40
41 require.Error(t, err)
42 assert.Contains(t, err.Error(), "Validation failed")
43 assert.NotContains(t, err.Error(), "Suggestion:")
44 })
45}
46
47func TestFieldLocationAlias(t *testing.T) {
48 loc := FieldLocation{File: "workflow.md", Line: 12, Column: 4}

Callers

nothing calls this directly

Calls 3

NewValidationErrorFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected