generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: If not already existant, create ftl-project.toml
and/or module config or secret
#1273
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1528684
Add nil check for module mapping
deniseli e63b5c9
error when ftl-project.toml does not exist
deniseli dbad3fc
create file if one does not already exist; ditto for module sections
deniseli 9dd3bc8
add most of the test cases
deniseli 2de255a
final test case
deniseli 2a1266c
final cleanup
deniseli c5a7dc7
Merge branch 'main' into dli/toml-panic-attacks
deniseli b83926d
fix lint errors and simplify config writing code
deniseli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,18 @@ func ConfigPaths(input []string) []string { | |
if len(input) > 0 { | ||
return input | ||
} | ||
path := filepath.Join(internal.GitRoot(""), "ftl-project.toml") | ||
path := GetDefaultConfigPath() | ||
_, err := os.Stat(path) | ||
if err == nil { | ||
return []string{path} | ||
} | ||
return []string{} | ||
} | ||
|
||
func GetDefaultConfigPath() string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. |
||
return filepath.Join(internal.GitRoot(""), "ftl-project.toml") | ||
} | ||
|
||
func LoadConfig(ctx context.Context, input []string) (Config, error) { | ||
logger := log.FromContext(ctx) | ||
configPaths := ConfigPaths(input) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually unnecessary -
pc.ConfigPaths()
will returnpc.GetDefaultConfigPath()
iflen(p.Config) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that! #1276