From cb84dc525d1480b287183a0feb84fcf92752d156 Mon Sep 17 00:00:00 2001 From: Stephan Schmidt Date: Sat, 23 Nov 2024 06:52:17 +0100 Subject: [PATCH] Add test --- .github/workflows/test.yml | 21 +++++++++++++++++++++ Makefile | 3 +++ go.mod | 4 ++++ go.sum | 9 +++++++++ internal/todo/domain/todo_test.go | 16 ++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 internal/todo/domain/todo_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ec76bc9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,21 @@ +name: Go package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.23 + + - name: Build + run: go build -v cmd/ + + - name: Test + run: go test -v ./... diff --git a/Makefile b/Makefile index 26fb7f2..3c4e12e 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,6 @@ run: go build -o ./bin/todo ./cmd/todo ./bin/todo + +test: + go test ./... diff --git a/go.mod b/go.mod index e44c443..8998360 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,14 @@ module ai-coding-comparison go 1.23.3 require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/mattn/go-sqlite3 v1.14.24 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.9.0 // indirect golang.org/x/text v0.20.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.6 // indirect gorm.io/gorm v1.25.12 // indirect ) diff --git a/go.sum b/go.sum index f17bf8c..1b58c9f 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,20 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE= gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= diff --git a/internal/todo/domain/todo_test.go b/internal/todo/domain/todo_test.go new file mode 100644 index 0000000..5fddb93 --- /dev/null +++ b/internal/todo/domain/todo_test.go @@ -0,0 +1,16 @@ +package domain + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTodoCreation(t *testing.T) { + todo := Todo{ + Title: "Test Todo", + } + + // Using testify's assert package for better readability + assert.Equal(t, "Test Todo", todo.Title, "Title should be 'Test Todo'") +}