package itemimage import ( "bytes" "image" "image/color" "image/png" "strings" "testing" "printer.backend/internal/model" ) const sampleItemSVG = ` ` func testPNG(w, h int) []byte { img := image.NewRGBA(image.Rect(0, 0, w, h)) for y := 0; y < h; y++ { for x := 0; x < w; x++ { img.Set(x, y, color.RGBA{uint8(x % 256), uint8(y % 256), 128, 255}) } } var buf bytes.Buffer _ = png.Encode(&buf, img) return buf.Bytes() } func TestEmbedReplacesGreenMask(t *testing.T) { spec := model.ItemSpec{WidthMM: 80, HeightMM: 80, BleedMM: 2, MarginMM: 5, PaddingMM: 3} out, err := Embed([]byte(sampleItemSVG), spec, testPNG(1, 1), "image/png") if err != nil { t.Fatal(err) } s := string(out) if strings.Contains(s, "#00FF00") || strings.Contains(s, "#00ff00") { t.Fatal("green placeholder should be replaced") } if !strings.Contains(s, ` maxSVG { t.Fatalf("embedded svg too large: %d bytes", len(out)) } } func TestEmbedInvalidSVG(t *testing.T) { spec := model.ItemSpec{WidthMM: 80, HeightMM: 80, BleedMM: 2, MarginMM: 5} _, err := Embed([]byte(""), spec, testPNG(1, 1), "image/png") if err == nil { t.Fatal("expected error") } }