From b84733ca333f2b1835aff8756bea91bb068f337e Mon Sep 17 00:00:00 2001 From: Dominik Winter Date: Thu, 25 Jan 2024 12:11:00 +0100 Subject: [PATCH 1/2] fix installation problems --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c13fde..b468047 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module genpno +module github.com/dominikwinter/genpno go 1.21.6 From 9d4fb360fcde846901327f4bcd53441ac88986d8 Mon Sep 17 00:00:00 2001 From: Dominik Winter Date: Thu, 25 Jan 2024 12:11:09 +0100 Subject: [PATCH 2/2] add unit tests --- Makefile | 8 +++++++- main_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 main_test.go diff --git a/Makefile b/Makefile index 768b912..f947134 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,19 @@ -.PHONY: default b build i install r release +.PHONY: default t test b build i install c clean r release default: build +t test: + go test -v + b build: go build i install: go install +c clean: + go mod tidy + r release: mkdir -p bin CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/genpno-macos-arm64 diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..9db27c1 --- /dev/null +++ b/main_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "testing" +) + +func Test_getRandomDate(t *testing.T) { + date := getRandomDate() + + if l := len(date); l != 8 { + t.Errorf("Date is not 8 characters long, but %d", l) + } +} + +func Test_getRandomThreeDigits(t *testing.T) { + three := getRandomThreeDigits(true) + + if l := len(three); l != 3 { + t.Errorf("Three is not 3 characters long, but %d", l) + } +} + +func Test_getChecksum(t *testing.T) { + date := "19800101" + three := "123" + + checksum := getChecksum(&date, &three) + + if l := len(checksum); l != 1 { + t.Errorf("Checksum is not 2 characters long, but %d", l) + } +}