Skip to content

Commit

Permalink
fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Dec 21, 2022
1 parent a4154f5 commit 726c88c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libs/log/lazy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package log

import (
tmbytes "github.com/line/ostracon/libs/bytes"
"github.com/stretchr/testify/require"
"testing"
)

func TestNewLazySprintf(t *testing.T) {
format := "echo:%s"
args := make([]interface{}, 0, 1)
args = append(args, "hello")
expected := LazySprintf{format: format, args: args}
actual := NewLazySprintf(format, args...)
require.Equal(t, expected.String(), actual.String())
}

func TestNewLazyBlockHash(t *testing.T) {
block := testHashable{}
expected := LazyBlockHash{block: block}
actual := NewLazyBlockHash(block)
require.Equal(t, expected.String(), actual.String())
}

type testHashable struct{}

func (testHashable) Hash() tmbytes.HexBytes {
return []byte{0}
}
30 changes: 30 additions & 0 deletions test/e2e/generator/generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"github.com/stretchr/testify/require"
"math/rand"
"testing"
)

func TestGenerate(t *testing.T) {
testcases := []struct {
name string
version string
}{
{
name: "empty version",
version: "",
},
{
name: "specify version",
version: "2",
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), tc.version)
require.NoError(t, err)
require.NotNil(t, manifests)
})
}
}
52 changes: 52 additions & 0 deletions test/e2e/generator/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"
)

func TestNewCLI(t *testing.T) {
tempDir, err := ioutil.TempDir("", "runner")
require.NoError(t, err)
defer os.RemoveAll(tempDir) //nolint:staticcheck
cmd := NewCLI()
testcases := []struct {
name string
wantErr bool
args []string
}{
{
name: "default",
wantErr: true,
args: []string{
"-d", tempDir,
},
},
{
name: "specify groups",
wantErr: true,
args: []string{
"-d", tempDir,
"-g", "1",
},
},
{
name: "specify version",
wantErr: true,
args: []string{
"-d", tempDir,
"-m", "1",
},
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
err := cmd.root.ParseFlags(tc.args)
require.NoError(t, err)
cmd.Run()
})
}
}

0 comments on commit 726c88c

Please sign in to comment.