generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: If not already existant, create
ftl-project.toml
and/or modul…
…e config or secret (#1273) Fixes issue #1174 Also tested manually by: ``` Open ftl-project.toml and confirm no module "echooo" is referenced $ ftl config set --inline echooo.HILLBILLY JENKINS Open ftl-project.toml and confirm this KV pair was added $ rm ftl-project.toml $ ftl config set --inline echooo.HILLBILLY JENKINS Open ftl-project.toml and confirm this KV pair was added Repeat for s/config/secret/ ```
- Loading branch information
Showing
5 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package configuration | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
"github.com/alecthomas/types/optional" | ||
|
||
"github.com/TBD54566975/ftl/common/projectconfig" | ||
"github.com/TBD54566975/ftl/internal/log" | ||
) | ||
|
||
func TestSet(t *testing.T) { | ||
defaultPath := projectconfig.GetDefaultConfigPath() | ||
origConfigBytes, err := os.ReadFile(defaultPath) | ||
assert.NoError(t, err) | ||
|
||
config := filepath.Join(t.TempDir(), "ftl-project.toml") | ||
existing, err := os.ReadFile("testdata/ftl-project.toml") | ||
assert.NoError(t, err) | ||
err = os.WriteFile(config, existing, 0600) | ||
assert.NoError(t, err) | ||
|
||
t.Run("ExistingModule", func(t *testing.T) { | ||
setAndAssert(t, "echo", []string{config}) | ||
}) | ||
t.Run("NewModule", func(t *testing.T) { | ||
setAndAssert(t, "echooo", []string{config}) | ||
}) | ||
t.Run("MissingTOMLFile", func(t *testing.T) { | ||
err := os.Remove(config) | ||
assert.NoError(t, err) | ||
setAndAssert(t, "echooooo", []string{}) | ||
err = os.WriteFile(defaultPath, origConfigBytes, 0600) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
|
||
func setAndAssert(t *testing.T, module string, config []string) { | ||
t.Helper() | ||
|
||
ctx := log.ContextWithNewDefaultLogger(context.Background()) | ||
|
||
cf, err := New(ctx, | ||
ProjectConfigResolver[Configuration]{Config: config}, | ||
[]Provider[Configuration]{ | ||
EnvarProvider[Configuration]{}, | ||
InlineProvider[Configuration]{Inline: true}, // Writer | ||
}) | ||
assert.NoError(t, err) | ||
|
||
var got *url.URL | ||
want := URL("inline://asdfasdf") | ||
err = cf.Set(ctx, Ref{Module: optional.Some[string](module), Name: "default"}, want) | ||
assert.NoError(t, err) | ||
err = cf.Get(ctx, Ref{Module: optional.Some[string](module), Name: "default"}, &got) | ||
assert.NoError(t, err) | ||
assert.Equal(t, want, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters