test saving edited conf
@@ -23,6 +23,8 @@ import (
"sort"
"testing"
+ "github.com/onflow/flow-cli/pkg/flowkit/config/json"
+
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/crypto"
"github.com/spf13/afero"
@@ -187,6 +189,7 @@ func generateSimpleProject() State {
}},
}
+ composer.AddConfigParser(json.NewParser())
p, err := newProject(&config, composer, af)
if err != nil {
fmt.Println(err)
@@ -553,3 +556,25 @@ func Test_ChangingState(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, (*pkey).String(), pk.String())
}
+
+func Test_Saving(t *testing.T) {
+ s := generateSimpleProject()
+
+ err := s.SaveEdited([]string{"a.json", "b.json"})
+ assert.EqualError(t, err, "specifying multiple paths is not supported when updating configuration")
+
+ err = s.SaveEdited([]string{config.GlobalPath(), config.DefaultPath})
+ assert.EqualError(t, err, "default configuration not found, please initialize it first or specify another configuration file")
+
+ err = s.SaveEdited([]string{"a.json"})
+ assert.NoError(t, err)
+
+ _ = afero.WriteFile(af.Fs, config.DefaultPath, []byte(`{
+ "networks": {
+ "foo": "localhost:3000"
+ }
+ }`), 0644)
+
+ err = s.SaveEdited([]string{config.GlobalPath(), config.DefaultPath})
+ assert.NoError(t, err)
+}
