mukan-ignite/ignite/pkg/confile/confile_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

53 lines
1.1 KiB
Go

package confile
import (
"io"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestAll(t *testing.T) {
cases := []struct {
name string
ec EncodingCreator
content string
}{
{"json", DefaultJSONEncodingCreator, `{"hello":"world"}`},
{"yaml", DefaultYAMLEncodingCreator, `hello: world`},
{"toml", DefaultTOMLEncodingCreator, `hello = "world"`},
}
type data struct {
Hello string `json:"hello" yaml:"hello" toml:"hello"`
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
file, err := os.CreateTemp("", "")
require.NoError(t, err)
defer func() {
file.Close()
os.Remove(file.Name())
}()
_, err = io.Copy(file, strings.NewReader(tt.content))
require.NoError(t, err)
cf := New(tt.ec, file.Name())
var d data
require.NoError(t, cf.Load(&d))
require.Equal(t, "world", d.Hello)
d.Hello = "cosmos"
require.NoError(t, cf.Save(d))
cf2 := New(tt.ec, file.Name())
var d2 data
require.NoError(t, cf2.Load(&d2))
require.Equal(t, "cosmos", d2.Hello)
})
}
}