|
| 1 | +package types |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func TestArtifactFetchError(t *testing.T) { |
| 13 | + inner := errors.New("connection refused") |
| 14 | + fetchErr := &ArtifactFetchError{ |
| 15 | + ArtifactType: "binary", |
| 16 | + URL: "https://storage.example.com/artifacts/abc123/binary.wasm?Expires=123&Signature=xyz", |
| 17 | + Err: inner, |
| 18 | + } |
| 19 | + |
| 20 | + t.Run("Error preserves full URL for internal debugging", func(t *testing.T) { |
| 21 | + assert.Contains(t, fetchErr.Error(), "Expires=123&Signature=xyz") |
| 22 | + assert.Contains(t, fetchErr.Error(), "binary.wasm") |
| 23 | + assert.Contains(t, fetchErr.Error(), "connection refused") |
| 24 | + }) |
| 25 | + |
| 26 | + t.Run("CustomerError is deterministic and omits URL details", func(t *testing.T) { |
| 27 | + msg := fetchErr.CustomerError() |
| 28 | + assert.Equal(t, "Internal error: failed to fetch workflow binary from storage. Contact support if this persists.", msg) |
| 29 | + assert.NotContains(t, msg, "Expires") |
| 30 | + assert.NotContains(t, msg, "Signature") |
| 31 | + assert.NotContains(t, msg, "example.com") |
| 32 | + }) |
| 33 | + |
| 34 | + t.Run("CustomerError reflects artifact type", func(t *testing.T) { |
| 35 | + configErr := &ArtifactFetchError{ArtifactType: "config", URL: "https://x.com/c?s=1", Err: inner} |
| 36 | + assert.Contains(t, configErr.CustomerError(), "workflow config") |
| 37 | + }) |
| 38 | + |
| 39 | + t.Run("Unwrap returns inner error", func(t *testing.T) { |
| 40 | + require.ErrorIs(t, fetchErr, inner) |
| 41 | + }) |
| 42 | + |
| 43 | + t.Run("errors.As matches through wrapping", func(t *testing.T) { |
| 44 | + wrapped := fmt.Errorf("outer: %w", fetchErr) |
| 45 | + var target *ArtifactFetchError |
| 46 | + require.ErrorAs(t, wrapped, &target) |
| 47 | + assert.Equal(t, "binary", target.ArtifactType) |
| 48 | + }) |
| 49 | +} |
0 commit comments