From adf4c9b92695db4a31ca3473d2fbacc3d5e1d82e Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 15 Nov 2023 05:45:14 +0000 Subject: [PATCH] Add test infrastructure This adds a Actions workflow for CI and a trivial unit test `project_test.go` to verify that the CI works. I envision that we could add more tests in coming weeks so that we won't break existing features while adding things. --- .github/workflows/test.yml | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 ++ project_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 project_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..bfd12f15 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +name: Test + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + cache: true + - name: Run tests + run: go test ./... + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.19' + cache: true + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55.1 + args: -v --timeout=10m diff --git a/go.mod b/go.mod index 77346574..ef81f8b2 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/go-git/go-git/v5 v5.10.0 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/shurcooL/githubv4 v0.0.0-20191006152017-6d1ea27df521 + github.com/stretchr/testify v1.8.1 golang.org/x/oauth2 v0.14.0 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 gopkg.in/yaml.v2 v2.4.0 @@ -53,6 +54,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect github.com/skeema/knownhosts v1.2.0 // indirect diff --git a/project_test.go b/project_test.go new file mode 100644 index 00000000..b4d1dcbd --- /dev/null +++ b/project_test.go @@ -0,0 +1,24 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestProjectFind(t *testing.T) { + pl := &ProjectList{ + Items: []DeployProject{ + { + ID: "testid", + Kind: "testkind", + }, + }, + } + want := DeployProject{ + ID: "test", + Kind: "testkind", + } + got := pl.Find("testid") + require.Equal(t, want, got) +}