Additional CI workflows #16

Merged
ashwin merged 5 commits from pm-add-workflows into main 2024-03-07 09:11:54 +00:00
4 changed files with 83 additions and 0 deletions
Showing only changes of commit af2b71abf0 - Show all commits

View File

@ -0,0 +1,19 @@
name: Unit Tests
on:
pull_request:
push:
branches:
- main
jobs:
test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21
check-latest: true
- uses: actions/checkout@v3
- name: Test
run: |
make test-unit

View File

@ -103,3 +103,6 @@ test-integration:
test-e2e:
$(MAKE) -C tests test-e2e
test-unit:
go test ./utils/... ./cmd/... -mod=readonly -test.v

28
cmd/laconic2d/cmd_test.go Normal file
View File

@ -0,0 +1,28 @@
package main_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client/flags"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"git.vdb.to/cerc-io/laconic2d/app"
"git.vdb.to/cerc-io/laconic2d/cmd/laconic2d/cmd"
)
func TestInitCmd(t *testing.T) {
rootCmd := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"init", // Test the init cmd
"localtestnet", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists
fmt.Sprintf("--%s=%s", flags.FlagChainID, "laconic_9000-1"),
})
err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome)
require.NoError(t, err)
}

33
utils/json_test.go Normal file
View File

@ -0,0 +1,33 @@
package utils
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAndValidateCIDGeneration(t *testing.T) {
testCases := []struct {
name string
content string
expected string
}{
{
"empty string", "", "",
},
{
"empty json", "{}", "bafyreigbtj4x7ip5legnfznufuopl4sg4knzc2cof6duas4b3q2fy6swua",
},
{
"test record", "{\"build_artifact_cid\":\"QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9\",\"repo_registration_record_cid\":\"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D\",\"tls_cert_cid\":\"QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\",\"type\":\"WebsiteRegistrationRecord\",\"url\":\"https://cerc.io\",\"version\":\"0.0.1\"}",
"bafyreiek4hnoqmits66bjyxswapplweuoqe4en2ux6u772o4y3askpd3ny",
},
}
for _, tc := range testCases {
newImpl, err := CIDFromJSONBytes([]byte(tc.content))
require.NoError(t, err)
require.Equal(t, tc.expected, newImpl)
}
}