Skip to content

Commit 1ec06b7

Browse files
theskyinflamesJaume
andauthored
fix: add real-crypto end-to-end test and regenerate stale mocks (#15)
- Add TestRealCryptoEncodingDecodingRoundTrip in lib/e2e_test.go that exercises the full encode->decode pipeline with real AES-256 (not mocks) - Regenerate zmock files whose import paths were stale (PR #12 changed module path, PR #14 regenerated mocks with old path before merging) - Update AGENTS.md to mark gotcha as resolved Co-authored-by: Jaume <jaume@example.com>
1 parent 981c95f commit 1ec06b7

4 files changed

Lines changed: 45 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## Gotchas & Sharp Edges
44

55
- ~~**`make generate` vendor dance:** It runs `go mod vendor` before `go generate ./...`, then removes `./vendor`. This may not work if vendor directory is gitignored or has stale contents.~~ ✅ Fixed — moq is now a `tool` dependency in `go.mod`, `//go:generate` uses `go run`, and `make generate` is just `go generate ./...`.
6+
- ~~**No real-crypto e2e test:** `lib/fixtures_test.go` uses generated mocks (`EncrypterMock`/`DecrypterMock`), so encryption/decryption round-trips are never tested with real AES-256. Don't assume integration coverage exists.~~ ✅ Fixed — `TestRealCryptoEncodingDecodingRoundTrip` in `lib/e2e_test.go` exercises full encode→decode pipeline with real AES-256.
67
- **Formatters are enforced:** `gofumpt` + `goimports` run as linters. Run `golangci-lint run` locally (or `make lint`) before pushing — it also verifies `go mod tidy` didn't change anything (`git diff --quiet go.mod go.sum`).
7-
- **No real-crypto e2e test:** `lib/fixtures_test.go` uses generated mocks (`EncrypterMock`/`DecrypterMock`), so encryption/decryption round-trips are never tested with real AES-256. Don't assume integration coverage exists.
88
- **WASM build typo:** `make build-wasm` outputs `assets/world2png.wasm` (missing 'd'). Preserve filename for backward compatibility with `word2pngUI`.
99
- **`os.Exit()` + non-standard code:** Both CLIs (`cmd/word2png/`, `cmd/png2word/`) call `os.Exit(-1)` on failure, skipping deferred cleanup. Handle with care.
1010
- **`cmd/wasm/` excluded from golangci-lint** (see `.golangci.yml` `build-tags: [infra]` and WASM build constraint).

lib/e2e_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package lib_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/theskyinflames/word2png/lib"
10+
)
11+
12+
func TestRealCryptoEncodingDecodingRoundTrip(t *testing.T) {
13+
const (
14+
passphrase = "I'm glad to meet you in this dark times."
15+
filePath = "./result.png"
16+
)
17+
18+
aes256 := lib.NewAES256(passphrase)
19+
20+
encoder := lib.NewEncoder(lib.Rune2Color(passphrase), aes256)
21+
encodedImage, err := encoder.Encode(words)
22+
require.NoError(t, err)
23+
require.NotEmpty(t, encodedImage)
24+
25+
f, err := os.Create(filePath)
26+
require.NoError(t, err)
27+
_, err = f.Write(encodedImage)
28+
require.NoError(t, err)
29+
require.NoError(t, f.Close())
30+
31+
defer func() {
32+
require.NoError(t, os.Remove(filePath))
33+
}()
34+
35+
encodedImage, err = os.ReadFile(filePath)
36+
require.NoError(t, err)
37+
decoder := lib.NewDecoder(lib.Rune2Color(passphrase), aes256)
38+
decodedWords, err := decoder.Decode(encodedImage)
39+
require.NoError(t, err)
40+
41+
require.Equal(t, words, decodedWords)
42+
}

lib/zmock_decoder_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/zmock_encoder_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)