-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support layered local variable definitions (#547)
* feat: support layered local variable definitions `with` can be a list of layers, each layer is merged in order and later layer can use values from previous layer. * docs: describe the layers in local context with
- Loading branch information
1 parent
545b736
commit 2df21fc
Showing
4 changed files
with
83 additions
and
7 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
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,52 @@ | ||
// Copyright 2023 PayPal Inc. | ||
|
||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT License was not distributed with this file, | ||
// you can obtain one at https://mit-license.org/. | ||
|
||
//go:build !integration | ||
// +build !integration | ||
|
||
package workflow | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ghodss/yaml" | ||
"github.com/golang/mock/gomock" | ||
"github.com/honeydipper/honeydipper/internal/config" | ||
"github.com/honeydipper/honeydipper/internal/workflow/mock_workflow" | ||
"github.com/honeydipper/honeydipper/pkg/dipper" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSessionLayered(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockHelper := mock_workflow.NewMockSessionStoreHelper(ctrl) | ||
s := NewSessionStore(mockHelper) | ||
|
||
// tear down | ||
defer delete(dipper.IDMapMetadata, &s.sessions) | ||
|
||
testDataSet := &config.DataSet{} | ||
testConfig := &config.Config{DataSet: testDataSet} | ||
mockHelper.EXPECT().GetConfig().AnyTimes().Return(testConfig) | ||
|
||
wf1 := &config.Workflow{} | ||
err := yaml.Unmarshal([]byte(` | ||
with: | ||
- foo: bar | ||
- foo+: " and " | ||
var1: $ctx.foo | ||
- foo+: bar2 | ||
- var2: $ctx.foo | ||
`), wf1) | ||
assert.Nil(t, err, "test config") | ||
w := s.newSession("", "uuid1", wf1).(*Session) | ||
w.prepare(&dipper.Message{}, nil, map[string]interface{}{}) | ||
assert.Equal(t, "bar and bar2", w.ctx["foo"], "inheriting from previous layer") | ||
assert.Equal(t, "bar", w.ctx["var1"], "using value from previous layer") | ||
assert.Equal(t, "bar and bar2", w.ctx["var2"], "using value from previous multiple layers") | ||
} |