-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#760) * Add `--delete-previous` option to `tk export` Documented in `exporting.md`. This option allows us to delete the previously exported manifests for an environment. This is useful when exporting a single environment and merging the result with an existing GitOps repository, rather than re-exporting all environments. I also added benchmark and a test for the export code. * Fix lint * Replace with `--merge-strategy` * PR comments * Validate possible merge values * Describe default behavior * Add test and extract the code. Linting should pass now
- Loading branch information
1 parent
8cc1e0a
commit c9d4827
Showing
8 changed files
with
429 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/grafana/tanka/pkg/tanka" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDetermineMergeStrategy(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
deprecatedFlag bool | ||
mergeStrategy string | ||
expected tanka.ExportMergeStrategy | ||
expectErr error | ||
}{ | ||
{ | ||
name: "default", | ||
deprecatedFlag: false, | ||
mergeStrategy: "", | ||
expected: tanka.ExportMergeStrategyNone, | ||
}, | ||
{ | ||
name: "deprecated flag set", | ||
deprecatedFlag: true, | ||
expected: tanka.ExportMergeStrategyFailConflicts, | ||
}, | ||
{ | ||
name: "both values set", | ||
deprecatedFlag: true, | ||
mergeStrategy: "fail-conflicts", | ||
expectErr: errors.New("cannot use --merge and --merge-strategy at the same time"), | ||
}, | ||
{ | ||
name: "fail-conflicts", | ||
mergeStrategy: "fail-on-conflicts", | ||
expected: tanka.ExportMergeStrategyFailConflicts, | ||
}, | ||
{ | ||
name: "replace-envs", | ||
mergeStrategy: "replace-envs", | ||
expected: tanka.ExportMergeStrategyReplaceEnvs, | ||
}, | ||
{ | ||
name: "bad value", | ||
mergeStrategy: "blabla", | ||
expectErr: errors.New("invalid merge strategy: \"blabla\""), | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result, err := determineMergeStrategy(tc.deprecatedFlag, tc.mergeStrategy) | ||
if tc.expectErr != nil { | ||
assert.EqualError(t, err, tc.expectErr.Error()) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.