aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile29
-rw-r--r--cmd/lulu/cost.go20
-rwxr-xr-xcmd/lulu/test18
-rw-r--r--cmd/lulu/testchecks/cost20
-rw-r--r--cmd/lulu/testchecks/jobs (renamed from cmd/lulu/testchecks/orders)0
-rw-r--r--cmd/lulu/tests/jobs1
-rw-r--r--cmd/lulu/tests/orders1
-rw-r--r--print_test.go9
9 files changed, 78 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index c8a5abb..5119e6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,11 @@
+/.build
/cmd/lulu/testerr
/cmd/lulu/testout
/.gen
/lulu
/spec.yml
+/.testcli
/testdata/clientkey
/testdata/clientsecret
+/.testpkg
/todo
diff --git a/Makefile b/Makefile
index 624e561..8e573aa 100644
--- a/Makefile
+++ b/Makefile
@@ -4,25 +4,36 @@ SRC = $(filter-out ${GEN} ${TEST}, $(wildcard *.go))
all: build lulu
-build: ${SRC} ${GEN}
- go build
+test: testpkg testcli
-testcli: lulu
- $(eval PATH=$(shell pwd):${PATH})
- cd cmd/lulu && ./test
+build: .build
+.build: ${SRC} ${GEN}
+ go build
+ touch $@
${GEN}: .gen
-
.gen: ${SRC}
- go generate && touch $@
+ go generate
+ touch $@
lulu: ${SRC} ${GEN} $(wildcard cmd/lulu/*.go)
go build ./cmd/$@
+testpkg: .testpkg
+.testpkg: ${SRC} ${GEN} ${TEST}
+ go test ./...
+ touch $@
+
+testcli: .testcli
+.testcli: lulu $(wildcard $(addprefix cmd/lulu/, test tests/* testdata/* testchecks/*))
+ $(eval PATH=$(shell pwd):${PATH})
+ cd cmd/lulu && ./test
+ touch $@
+
spec.yml:
curl -L -o $@ 'https://api.lulu.com/api-docs/openapi-specs/openapi_public.yml'
clean:
- rm -rf ${GEN} lulu .gen cmd/lulu/testerr cmd/lulu/testout
+ rm -rf ${GEN} lulu .build .gen .testpkg .testcli cmd/lulu/testerr cmd/lulu/testout
-.PHONY: testcli
+.PHONY: all build test testpkg testcli
diff --git a/cmd/lulu/cost.go b/cmd/lulu/cost.go
index 8599340..93c3ab4 100644
--- a/cmd/lulu/cost.go
+++ b/cmd/lulu/cost.go
@@ -3,8 +3,10 @@ package main
import (
"encoding/json"
"fmt"
+ "os"
"regexp"
"strconv"
+ "text/tabwriter"
"github.com/alecthomas/kong"
@@ -38,8 +40,21 @@ func (cmd *CostCmd) Run(cli *kong.Kong, clnt *lulu.Client) error {
if err != nil {
return err
}
- // TODO: -v flag to print everything
- fmt.Printf("total: %s %s\n", cost.TotalCostInclTax, cost.Currency)
+
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
+ for _, fee := range cost.Fees {
+ fmt.Fprintf(w, "fee %s %s:\t%s %s\t\n", fee.Type, fee.Sku, fee.TotalCostExclTax, fee.Currency)
+ }
+ for i, item := range cost.LineItemCosts {
+ fmt.Fprintf(w, "item %d:\t%s %s\t\n", i, item.TotalCostExclTax, cost.Currency)
+ }
+ fmt.Fprintf(w, "shipping:\t%s %s\t\n", cost.ShipCost.TotalCostExclTax, cost.Currency)
+ fmt.Fprintf(w, "fulfillment:\t%s %s\t\n", cost.FulfillmentCost.TotalCostExclTax, cost.Currency)
+ fmt.Fprintf(w, "discount:\t%s %s\t\n", cost.TotalDiscount, cost.Currency)
+ fmt.Fprintf(w, "tax:\t%s %s\t\n", cost.TotalTax, cost.Currency)
+ fmt.Fprintf(w, "total:\t%s %s\t\n", cost.TotalCostInclTax, cost.Currency)
+ w.Flush()
+
if len(addrVal.Warnings) > 0 {
j, err := json.Marshal(addrVal)
if err != nil {
@@ -47,6 +62,7 @@ func (cmd *CostCmd) Run(cli *kong.Kong, clnt *lulu.Client) error {
}
cli.Errorf("%s\n", j)
}
+
return nil
}
diff --git a/cmd/lulu/test b/cmd/lulu/test
index 8c29a2f..e446356 100755
--- a/cmd/lulu/test
+++ b/cmd/lulu/test
@@ -2,10 +2,13 @@
set -u
+flags="-e -u"
+
[[ ! -d testout ]] && mkdir testout
[[ ! -d testerr ]] && mkdir testerr
-for test in tests/*
+[[ $# -gt 0 ]] && tests="tests/$1" || tests=tests/*
+for test in $tests
do
echo $test...
base=${test##*/}
@@ -14,7 +17,7 @@ do
out=testout/$base
err=testerr/$base
if [ -f $want ]; then # check against expected output
- sh $test >$out 2>$err
+ sh ${flags} $test >$out 2>$err
if ! cmp -s $want $out
then
echo "FAIL $test: <Expected >Actual"
@@ -22,19 +25,22 @@ do
exit 1
fi
elif [ -f $check ]; then # use script to check output
- sh $test >$out 2>$err
+ sh ${flags} $test >$out 2>$err
echo "checking with $check..." >>$err
- if ! sh $check $out >>$err
+ if ! sh ${flags} $check $out >>$err
then
echo "FAIL $test: check failed: $check"
exit 1
fi
- else # test should fail
- if sh $test >$out 2>$err
+ elif [ -f $test ]; then # test should fail
+ if sh ${flags} $test >$out 2>$err
then
echo "FAIL $test: expected error; got \"$(cat $out)\""
exit 1
fi
+ else
+ echo "FAIL: does not exist: \"$test\""
+ exit 1
fi
done
diff --git a/cmd/lulu/testchecks/cost b/cmd/lulu/testchecks/cost
index 5ce1d48..479bdf4 100644
--- a/cmd/lulu/testchecks/cost
+++ b/cmd/lulu/testchecks/cost
@@ -1 +1,19 @@
-grep -E '^total: [1-9][0-9]*(\.[0-9]+)? [A-Z]{3}$' $1
+money='[0-9]+(\.[0-9]+)? [A-Z]{3}'
+for field in "item 0" "item 1" "shipping" "fulfillment" "discount" "tax" "total"
+do
+ re="$(printf '^%s: +%s *$' "${field}" "${money}")"
+ echo "$re"
+ grep -E "$re" $1
+done
+grep -E -v '^item [^01]' $1
+awk '
+ # Ensure sum of fields equals total.
+ !/^total/ { wantTotal += $(NF-1) }
+ /^total/ {
+ gotTotal = $(NF-1)
+ if (gotTotal > wantTotal+1e7 || gotTotal < wantTotal-1e7) {
+ printf "total (%f) does not match expected (%f)\n", gotTotal, wantTotal >>"/dev/stderr"
+ exit 1
+ }
+ }
+' $1
diff --git a/cmd/lulu/testchecks/orders b/cmd/lulu/testchecks/jobs
index 2d90544..2d90544 100644
--- a/cmd/lulu/testchecks/orders
+++ b/cmd/lulu/testchecks/jobs
diff --git a/cmd/lulu/tests/jobs b/cmd/lulu/tests/jobs
new file mode 100644
index 0000000..8c6365d
--- /dev/null
+++ b/cmd/lulu/tests/jobs
@@ -0,0 +1 @@
+lulu -s jobs
diff --git a/cmd/lulu/tests/orders b/cmd/lulu/tests/orders
deleted file mode 100644
index 910948c..0000000
--- a/cmd/lulu/tests/orders
+++ /dev/null
@@ -1 +0,0 @@
-lulu -s orders
diff --git a/print_test.go b/print_test.go
index 2ff6209..b5d87f4 100644
--- a/print_test.go
+++ b/print_test.go
@@ -224,10 +224,10 @@ func TestReprint(t *testing.T) {
require.NoError(t, err)
require.Len(t, job2.LineItems, 1)
item1, item2 := job1.LineItems[0], job2.LineItems[0]
- require.Equal(t, item1.Title, item2.Title)
+ require.Equal(t, item1.PrintableId, item2.PrintableId)
require.Equal(t, item1.ExternalId, item2.ExternalId)
+ require.Equal(t, item1.Title, item2.Title)
require.Equal(t, item1.Quantity, item2.Quantity)
- require.Equal(t, item1.PrintableId, item2.PrintableId)
require.Equal(t, item1.Mfg, item2.Mfg)
}
@@ -247,8 +247,9 @@ func TestGetPrintJob(t *testing.T) {
job2, err := c.GetPrintJob(job1.Id)
require.NoError(t, err)
- // Ignore timestamp because job may have been modified between
- // creation and retrieval time
+ // Ignore timestamp because job gets marked as 'modified' between
+ // creation and retrieval time even if it hasn't actually
+ // changed.
job2.Modified = job1.Modified
require.Equal(t, job1, job2)