diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-14 18:26:01 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-14 18:26:01 -0400 |
| commit | 7ffc98c007601921db0677fc07c9779f71bb3499 (patch) | |
| tree | 84ef660183e9f89cad6ff3ac5f14a338aac86403 | |
| parent | 28a5aa8c8e7a61dbf06a2cd72ea1bfdee8e67ba6 (diff) | |
| download | lulu-7ffc98c007601921db0677fc07c9779f71bb3499.zip | |
cli: test validate-interior
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | cmd/lulu/main.go | 20 | ||||
| -rwxr-xr-x | cmd/lulu/test | 19 | ||||
| -rw-r--r-- | cmd/lulu/testchecks/vi | 3 | ||||
| -rw-r--r-- | cmd/lulu/tests/vi | 1 | ||||
| -rw-r--r-- | cmd/lulu/tests/vi_wrongsize | 2 | ||||
| -rw-r--r-- | interior.go | 4 | ||||
| -rw-r--r-- | interior_test.go | 37 | ||||
| -rw-r--r-- | testdata/interiorvalidationreq.json | 4 | ||||
| -rw-r--r-- | testdata/interiorvalidationresp.json | 10 |
11 files changed, 73 insertions, 32 deletions
@@ -1,3 +1,4 @@ +/cmd/lulu/testerr /cmd/lulu/testout /.gen /lulu @@ -7,7 +7,7 @@ all: build lulu build: ${SRC} ${GEN} go build -testcli: lulu cmd/lulu/test $(wildcard cmd/lulu/tests/*) $(wildcard cmd/lulu/testdata/*) +testcli: lulu $(eval PATH=$(shell pwd):${PATH}) cd cmd/lulu && ./test @@ -23,6 +23,6 @@ spec.yml: curl -L -o $@ 'https://api.lulu.com/api-docs/openapi-specs/openapi_public.yml' clean: - cat .gitignore | xargs -I{} sh -c "rm -rf ./{}" + rm -rf ${GEN} lulu .gen cmd/lulu/testerr cmd/lulu/testout .PHONY: testcli diff --git a/cmd/lulu/main.go b/cmd/lulu/main.go index 6e6f146..8d3527b 100644 --- a/cmd/lulu/main.go +++ b/cmd/lulu/main.go @@ -118,7 +118,7 @@ func validateInterior(name string, clnt *lulu.Client, args []string) { basic bool url url.URL mfg lulu.PkgId - timeout time.Duration + timeout = defaultTimeout ) basicFlag := Flag{&boolValue{p: &basic}, "basic", "Basic validation without pod_package_id manufacturing options", false} @@ -151,7 +151,21 @@ func validateInterior(name string, clnt *lulu.Client, args []string) { if err != nil { lg.Fatal(err) } - fmt.Println(val) // TODO: output format? + + fmt.Println("status:", val.Status) + fmt.Println("id:", val.Id) + if len(val.ValidPkgIds) > 0 { + fmt.Printf("valid %ss: %v\n", typeName(val.ValidPkgIds[0]), val.ValidPkgIds) + } + + for _, err := range val.Errors { + lg.Printf("lulu error: %s\n", err) + } + if len(val.Errors) > 0 || + (basic && val.Status != lulu.InteriorStatusValidated) || + val.Status != lulu.InteriorStatusNormalized { + os.Exit(1) + } } func validateCover(name string, clnt *lulu.Client, args []string) { @@ -159,7 +173,7 @@ func validateCover(name string, clnt *lulu.Client, args []string) { url url.URL mfg lulu.PkgId nPages uint - timeout time.Duration + timeout = defaultTimeout ) fs := newFlagSet(name, []Flag{ Flag{&urlValue{p: &url}, "url", "URL of cover file for Lulu to download", true}, diff --git a/cmd/lulu/test b/cmd/lulu/test index e819005..375cc95 100755 --- a/cmd/lulu/test +++ b/cmd/lulu/test @@ -3,22 +3,33 @@ set -u [[ ! -d testout ]] && mkdir testout +[[ ! -d testerr ]] && mkdir testerr for test in tests/* do base=${test##*/} want=testdata/$base + check=testchecks/$base out=testout/$base - if [ -f $want ]; then - sh $test >$out 2>/dev/null + err=testerr/$base + if [ -f $want ]; then # check against expected output + sh $test >$out 2>$err if ! cmp -s $want $out then echo "FAIL $test: <Expected >Actual" diff $want $out exit 1 fi - else - if sh $test >$out 2>/dev/null + elif [ -f $check ]; then # use script to check output + sh $test >$out 2>$err + echo "checking with $check..." >>$err + if ! sh $check $out >>$err + then + echo "FAIL $test: check failed: $check" + exit 1 + fi + else # test should fail + if sh $test >$out 2>$err then echo "FAIL $test: expected error; got \"$(cat $out)\"" exit 1 diff --git a/cmd/lulu/testchecks/vi b/cmd/lulu/testchecks/vi new file mode 100644 index 0000000..5fe44a8 --- /dev/null +++ b/cmd/lulu/testchecks/vi @@ -0,0 +1,3 @@ +grep '^status: NORMALIZED$' <$1 +grep '^id: [1-9][0-9]*$' <$1 +grep '^valid PkgIds: \[[A-Z0-9. ]\+\]$' <$1 diff --git a/cmd/lulu/tests/vi b/cmd/lulu/tests/vi new file mode 100644 index 0000000..8a074c3 --- /dev/null +++ b/cmd/lulu/tests/vi @@ -0,0 +1 @@ +lulu -s vi -mfg 0600X0900.BW.PRE.PB.060UW444.MXX -url https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1 -t 30s diff --git a/cmd/lulu/tests/vi_wrongsize b/cmd/lulu/tests/vi_wrongsize new file mode 100644 index 0000000..b6932af --- /dev/null +++ b/cmd/lulu/tests/vi_wrongsize @@ -0,0 +1,2 @@ +# should fail with "The book size you selected does not match the page size in the file you uploaded" +lulu -s vi -mfg 0583X0827.BW.PRE.PB.060UW444.MXX -url https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1 diff --git a/interior.go b/interior.go index 98ff4d2..e9d183b 100644 --- a/interior.go +++ b/interior.go @@ -36,10 +36,10 @@ type validateInteriorBasicReq struct { // InteriorValidation contains the validation status of an interior file. type InteriorValidation struct { - Id uint + Id uint `json:"id"` SrcUrl string `json:"source_url"` NPages uint `json:"page_count"` - Errors string + Errors []string `json:"errors"` Status InteriorValidationStatus ValidPkgIds []PkgId `json:"valid_pod_package_ids"` } diff --git a/interior_test.go b/interior_test.go index 110afb2..804e487 100644 --- a/interior_test.go +++ b/interior_test.go @@ -3,16 +3,16 @@ package lulu import ( "context" "testing" + _ "embed" "github.com/stretchr/testify/require" ) +//go:embed testdata/interiorvalidationreq.json +var interiorValidationReqJson string + func TestMarshalValidateInteriorReq(t *testing.T) { t.Parallel() - want := `{ - "source_url": "https://example.com/interior.pdf", - "pod_package_id": "0850X1100.BW.STD.LW.060UW444.MNG" -}` req := validateInteriorReq{ "https://example.com/interior.pdf", PkgId{ @@ -25,7 +25,7 @@ func TestMarshalValidateInteriorReq(t *testing.T) { NavyLinen, GoldFoil}, } - requireMarshalJsonEq(t, want, req) + requireMarshalJsonEq(t, interiorValidationReqJson, req) } func TestMarshalValidateInteriorBasicReq(t *testing.T) { @@ -35,25 +35,20 @@ func TestMarshalValidateInteriorBasicReq(t *testing.T) { validateInteriorBasicReq{"https://example.com/interior.pdf"}) } +//go:embed testdata/interiorvalidationresp.json +var interiorValidationRespJson string + func TestUnmarshalInteriorValidation(t *testing.T) { t.Parallel() - data := `{ - "id": 1, - "source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", - "page_count": 210, - "errors": null, - "status": "VALIDATING", - "valid_pod_package_ids": null -}` - want := InteriorValidation{ - 1, - "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", - 210, - "", - InteriorStatusValidating, - nil, + val := InteriorValidation{ + Id: 1, + SrcUrl: "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", + NPages: 210, + Errors: []string{"Book Size: The book size you selected does not match the page size in the file you uploaded."}, + Status: InteriorStatusValidating, + ValidPkgIds: nil, } - requireUnmarshalJsonEq(t, want, data) + requireUnmarshalJsonEq(t, val, interiorValidationRespJson) } func TestStartInteriorValidation(t *testing.T) { diff --git a/testdata/interiorvalidationreq.json b/testdata/interiorvalidationreq.json new file mode 100644 index 0000000..a5301a8 --- /dev/null +++ b/testdata/interiorvalidationreq.json @@ -0,0 +1,4 @@ +{ + "source_url": "https://example.com/interior.pdf", + "pod_package_id": "0850X1100.BW.STD.LW.060UW444.MNG" +} diff --git a/testdata/interiorvalidationresp.json b/testdata/interiorvalidationresp.json new file mode 100644 index 0000000..90a7b09 --- /dev/null +++ b/testdata/interiorvalidationresp.json @@ -0,0 +1,10 @@ +{ + "id": 1, + "source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", + "page_count": 210, + "errors": [ + "Book Size: The book size you selected does not match the page size in the file you uploaded." + ], + "status": "VALIDATING", + "valid_pod_package_ids": null +} |