repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / shared / storage
Eric Bower · 20 Aug 24

proxy_test.go

  1package storage
  2
  3import (
  4	"testing"
  5
  6	"github.com/google/go-cmp/cmp"
  7)
  8
  9type Fixture struct {
 10	name   string
 11	input  string
 12	expect *ImgProcessOpts
 13}
 14
 15func TestUriToImgProcessOpts(t *testing.T) {
 16	fixtures := []Fixture{
 17		{
 18			name:  "imgs_api_height",
 19			input: "/x500",
 20			expect: &ImgProcessOpts{
 21				Ratio: &Ratio{
 22					Width:  0,
 23					Height: 500,
 24				},
 25			},
 26		},
 27		{
 28			name:  "imgs_api_width",
 29			input: "/500x",
 30			expect: &ImgProcessOpts{
 31				Ratio: &Ratio{
 32					Width:  500,
 33					Height: 0,
 34				},
 35			},
 36		},
 37		{
 38			name:  "imgs_api_both",
 39			input: "/500x600",
 40			expect: &ImgProcessOpts{
 41				Ratio: &Ratio{
 42					Width:  500,
 43					Height: 600,
 44				},
 45			},
 46		},
 47		{
 48			name:  "imgproxy_height",
 49			input: "/s::500",
 50			expect: &ImgProcessOpts{
 51				Ratio: &Ratio{
 52					Width:  0,
 53					Height: 500,
 54				},
 55			},
 56		},
 57		{
 58			name:  "imgproxy_width",
 59			input: "/s:500",
 60			expect: &ImgProcessOpts{
 61				Ratio: &Ratio{
 62					Width:  500,
 63					Height: 0,
 64				},
 65			},
 66		},
 67		{
 68			name:  "imgproxy_both",
 69			input: "/s:500:600",
 70			expect: &ImgProcessOpts{
 71				Ratio: &Ratio{
 72					Width:  500,
 73					Height: 600,
 74				},
 75			},
 76		},
 77		{
 78			name:  "imgproxy_quality",
 79			input: "/q:80",
 80			expect: &ImgProcessOpts{
 81				Quality: 80,
 82			},
 83		},
 84		{
 85			name:  "imgproxy_rotate",
 86			input: "/rt:90",
 87			expect: &ImgProcessOpts{
 88				Rotate: 90,
 89			},
 90		},
 91	}
 92
 93	for _, fixture := range fixtures {
 94		t.Run(fixture.name, func(t *testing.T) {
 95			results, err := UriToImgProcessOpts(fixture.input)
 96			if err != nil {
 97				t.Error(err)
 98			}
 99			if cmp.Equal(results, fixture.expect) == false {
100				//nolint
101				t.Fatalf(cmp.Diff(fixture.expect, results))
102			}
103		})
104	}
105}