Additional CI workflows #16
19
.gitea/workflows/test-unit.yml
Normal file
19
.gitea/workflows/test-unit.yml
Normal 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
|
3
Makefile
3
Makefile
@ -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
28
cmd/laconic2d/cmd_test.go
Normal 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
33
utils/json_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user