master
1package generate
2
3import (
4 "testing"
5)
6
7func TestGenerateQRCode(t *testing.T) {
8 tests := []struct {
9 name string
10 url string
11 wantErr bool
12 }{
13 {
14 name: "valid URL",
15 url: "https://example.com",
16 wantErr: false,
17 },
18 {
19 name: "empty URL",
20 url: "",
21 wantErr: true, // QR code library doesn't accept empty strings
22 },
23 }
24
25 for _, tt := range tests {
26 t.Run(tt.name, func(t *testing.T) {
27 png, stdout, err := generateQRCode(tt.url)
28 if (err != nil) != tt.wantErr {
29 t.Errorf("generateQRCode() error = %v, wantErr %v", err, tt.wantErr)
30 return
31 }
32
33 if !tt.wantErr {
34 if len(png) == 0 {
35 t.Error("generateQRCode() returned empty PNG")
36 }
37 if len(stdout) == 0 {
38 t.Error("generateQRCode() returned empty stdout")
39 }
40 }
41 })
42 }
43}