-
Notifications
You must be signed in to change notification settings - Fork 0
fix(provider): resync built-in provider configs from embedded YAML #508
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
22d8a09
fix(provider): resync built-in provider configs from embedded YAML
skevetter 4c28ac5
style(provider): use DockerDriver constant in tests
skevetter f097123
docs(provider): trim verbose comments in internal-provider refresh
skevetter 3cd31ad
fix(provider): refresh built-ins by source id, not name
skevetter 3e3f57c
style(provider): extract stale helper-sh command constant
skevetter 1e34a49
fix(provider): overlay only exec on internal refresh
skevetter 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 hidden or 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 hidden or 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,135 @@ | ||
| package provider | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/devsy-org/devsy/pkg/config" | ||
| "github.com/devsy-org/devsy/pkg/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // staleHelperShCommand is the removed "helper sh" exec.command wrapper that | ||
| // stale provider.json files carry before a refresh rewrites them. | ||
| const staleHelperShCommand = `"${DEVSY}" helper sh -c "${COMMAND}"` | ||
|
|
||
| const staleVersion = "v0.0.0-stale" | ||
|
|
||
| // TestLoadProviderConfig_RefreshesInternalProvider verifies that a stored | ||
| // built-in provider config with a stale exec.command (e.g. the removed | ||
| // "helper sh" wrapper baked in before a CLI rename) has its exec block | ||
| // refreshed from the embedded provider definition on load. | ||
| func TestLoadProviderConfig_RefreshesInternalProvider(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| stale := &ProviderConfig{ | ||
| Name: DockerDriver, | ||
| Version: staleVersion, | ||
| Source: ProviderSource{Internal: true, Raw: DockerDriver}, | ||
| Exec: ProviderCommands{ | ||
| Command: []string{staleHelperShCommand}, | ||
| }, | ||
| } | ||
| require.NoError(t, SaveProviderConfig(config.DefaultContext, stale)) | ||
|
|
||
| loaded, err := LoadProviderConfig(config.DefaultContext, DockerDriver) | ||
| require.NoError(t, err) | ||
| require.Len(t, loaded.Exec.Command, 1) | ||
| require.NotContains(t, loaded.Exec.Command[0], "helper sh", | ||
| "internal provider must be refreshed from embedded yaml, not the stale stored config") | ||
| require.True(t, strings.Contains(loaded.Exec.Command[0], "internal sh"), | ||
| "refreshed command should use the current 'internal sh' wrapper") | ||
| } | ||
|
|
||
| // TestLoadProviderConfig_PreservesCustomizations verifies the exec refresh | ||
| // overlays only the embedded exec block, leaving a user's custom Name and | ||
| // resolved Options intact (a built-in added with `--name`/`--option`). | ||
| func TestLoadProviderConfig_PreservesCustomizations(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| stored := &ProviderConfig{ | ||
| Name: "my-docker", | ||
| Version: staleVersion, | ||
| Source: ProviderSource{Internal: true, Raw: DockerDriver}, | ||
| Options: map[string]*types.Option{ | ||
| "DOCKER_PATH": {Default: "podman"}, | ||
| }, | ||
| Exec: ProviderCommands{ | ||
| Command: []string{staleHelperShCommand}, | ||
| }, | ||
| } | ||
| require.NoError(t, SaveProviderConfig(config.DefaultContext, stored)) | ||
|
|
||
| loaded, err := LoadProviderConfig(config.DefaultContext, "my-docker") | ||
| require.NoError(t, err) | ||
| require.Equal(t, "my-docker", loaded.Name, "custom provider name must survive refresh") | ||
| require.Equal(t, "v0.0.0-stale", loaded.Version, "stored version must survive refresh") | ||
| require.Equal(t, "podman", loaded.Options["DOCKER_PATH"].Default, | ||
| "resolved options must survive refresh") | ||
| require.NotContains(t, loaded.Exec.Command[0], "helper sh", | ||
| "exec block must still be refreshed from embedded yaml") | ||
| } | ||
|
|
||
| // TestLoadProviderConfig_RefreshesProBySourceID guards the case where a | ||
| // built-in's provider Name differs from its source id: pro is stored as | ||
| // "devsy-pro" but keyed in the embedded map as "pro". Refresh must key off | ||
| // Source.Raw (the source id), not Name, or the pro provider keeps a stale config. | ||
| func TestLoadProviderConfig_RefreshesProBySourceID(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| stale := &ProviderConfig{ | ||
| Name: "devsy-pro", | ||
| Version: staleVersion, | ||
| Source: ProviderSource{Internal: true, Raw: "pro"}, | ||
| Exec: ProviderCommands{Daemon: &DaemonCommands{Start: []string{"stale start"}}}, | ||
| } | ||
| require.NoError(t, SaveProviderConfig(config.DefaultContext, stale)) | ||
|
|
||
| loaded, err := LoadProviderConfig(config.DefaultContext, "devsy-pro") | ||
| require.NoError(t, err) | ||
| require.NotNil(t, loaded.Exec.Daemon, "pro exec must be refreshed from embedded yaml") | ||
| require.NotEqual(t, []string{"stale start"}, []string(loaded.Exec.Daemon.Start), | ||
| "pro provider exec must be refreshed from embedded yaml via Source.Raw") | ||
| } | ||
|
|
||
| // TestLoadProviderConfig_UnknownInternalFallsBack ensures an internal provider | ||
| // whose name is not a built-in (e.g. a removed/renamed provider lingering on | ||
| // disk) falls back to the stored config rather than failing or returning empty. | ||
| func TestLoadProviderConfig_UnknownInternalFallsBack(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| stored := &ProviderConfig{ | ||
| Name: "retired-provider", | ||
| Version: "v0.0.1", | ||
| Source: ProviderSource{Internal: true, Raw: "retired-provider"}, | ||
| Exec: ProviderCommands{ | ||
| Command: []string{`"${DEVSY}" internal sh -c "${COMMAND}"`}, | ||
| }, | ||
| } | ||
| require.NoError(t, SaveProviderConfig(config.DefaultContext, stored)) | ||
|
|
||
| loaded, err := LoadProviderConfig(config.DefaultContext, "retired-provider") | ||
| require.NoError(t, err) | ||
| require.Equal(t, stored.Exec.Command, loaded.Exec.Command) | ||
| require.Equal(t, "v0.0.1", loaded.Version) | ||
| } | ||
|
|
||
| // TestLoadProviderConfig_PreservesExternalProvider ensures non-internal | ||
| // providers are loaded verbatim from disk (no embedded refresh). | ||
| func TestLoadProviderConfig_PreservesExternalProvider(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| external := &ProviderConfig{ | ||
| Name: DockerDriver, | ||
| Version: "v0.0.1", | ||
| Source: ProviderSource{Github: "some-org/some-provider"}, | ||
| Exec: ProviderCommands{ | ||
| Command: []string{staleHelperShCommand}, | ||
| }, | ||
| } | ||
| require.NoError(t, SaveProviderConfig(config.DefaultContext, external)) | ||
|
|
||
| loaded, err := LoadProviderConfig(config.DefaultContext, DockerDriver) | ||
| require.NoError(t, err) | ||
| require.Equal(t, external.Exec.Command, loaded.Exec.Command) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.