-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8387 from evanchaoli/load-var-inter-file
load_var to support var interpolate
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package creds | ||
|
||
import ( | ||
"github.com/concourse/concourse/atc" | ||
"github.com/concourse/concourse/vars" | ||
) | ||
|
||
type LoadVarPlan struct { | ||
variablesResolver vars.Variables | ||
rawPlan atc.LoadVarPlan | ||
} | ||
|
||
func NewLoadVarPlan(variables vars.Variables, plan atc.LoadVarPlan) LoadVarPlan { | ||
return LoadVarPlan{ | ||
variablesResolver: variables, | ||
rawPlan: plan, | ||
} | ||
} | ||
|
||
func (s LoadVarPlan) Evaluate() (atc.LoadVarPlan, error) { | ||
var plan atc.LoadVarPlan | ||
|
||
// Name of load_var should not be interpolated. | ||
name := s.rawPlan.Name | ||
|
||
err := evaluate(s.variablesResolver, s.rawPlan, &plan) | ||
if err != nil { | ||
return atc.LoadVarPlan{}, err | ||
} | ||
plan.Name = name | ||
|
||
return plan, nil | ||
} |
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,40 @@ | ||
package creds_test | ||
|
||
import ( | ||
"github.com/concourse/concourse/atc" | ||
"github.com/concourse/concourse/atc/creds" | ||
"github.com/concourse/concourse/vars" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Evaluate", func() { | ||
var plan creds.LoadVarPlan | ||
|
||
BeforeEach(func() { | ||
variables := vars.StaticVariables{ | ||
"var-name": "vn-is", | ||
"filename": "fn-is", | ||
"var-format": "json", | ||
} | ||
plan = creds.NewLoadVarPlan(variables, atc.LoadVarPlan{ | ||
Name: "some-((var-name))-ok", | ||
File: "some-((filename))-ok", | ||
Format: "((var-format))", | ||
}) | ||
}) | ||
|
||
Describe("Evaluate", func() { | ||
It("parses variables", func() { | ||
result, err := plan.Evaluate() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(result).To(Equal(atc.LoadVarPlan{ | ||
Name: "some-((var-name))-ok", // Name should not be interpolated. | ||
File: "some-fn-is-ok", | ||
Format: "json", | ||
})) | ||
}) | ||
}) | ||
}) |
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