mukan-ignite/ignite/pkg/tarball/tarball_test.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

97 lines
1.9 KiB
Go

package tarball
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestExtractFile(t *testing.T) {
exampleJSON, err := os.ReadFile("testdata/example.json")
require.NoError(t, err)
type args struct {
tarballPath string
file string
}
tests := []struct {
name string
args args
want []byte
wantPath string
err error
}{
{
name: "simple read",
args: args{
tarballPath: "testdata/example.tar.gz",
file: "example.json",
},
want: exampleJSON,
wantPath: "genesis/example.json",
},
{
name: "read from root",
args: args{
tarballPath: "testdata/example-root.tar.gz",
file: "example.json",
},
want: exampleJSON,
wantPath: "example.json",
},
{
name: "read from subfolder",
args: args{
tarballPath: "testdata/example-subfolder.tar.gz",
file: "example.json",
},
want: exampleJSON,
wantPath: "config/genesis/example.json",
},
{
name: "empty folders",
args: args{
tarballPath: "testdata/example-empty.tar.gz",
file: "example.json",
},
err: ErrGzipFileNotFound,
},
{
name: "invalid file",
args: args{
tarballPath: "testdata/invalid_file",
file: "example.json",
},
err: ErrNotGzipType,
},
{
name: "invalid file extension",
args: args{
tarballPath: "testdata/example.json",
file: "example.json",
},
err: ErrNotGzipType,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tarball, err := os.Open(tt.args.tarballPath)
require.NoError(t, err)
var buf bytes.Buffer
gotPath, err := ExtractFile(tarball, &buf, tt.args.file)
if tt.err != nil {
require.Error(t, err)
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
require.Equal(t, tt.wantPath, gotPath)
require.NoError(t, err)
require.Equal(t, tt.want, buf.Bytes())
})
}
}