Skip to content
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

Change env var prefix to JUMPPAD_VAR_ #252

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/config/zz_hclparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
// setupHCLConfig configures the HCLConfig package and registers the custom types
func NewParser(callback hclconfig.WalkCallback, variables map[string]string, variablesFiles []string) *hclconfig.Parser {
cfg := hclconfig.DefaultOptions()
cfg.Callback = callback

cfg.ParseCallback = callback

Check failure on line 41 in pkg/config/zz_hclparser.go

View workflow job for this annotation

GitHub Actions / Unit Test

cfg.ParseCallback undefined (type *hclconfig.ParserOptions has no field or method ParseCallback)
cfg.VariableEnvPrefix = "JUMPPAD_VAR_"
cfg.Variables = variables
cfg.VariablesFiles = variablesFiles

Expand Down
8 changes: 4 additions & 4 deletions pkg/jumppad/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Clients contains clients which are responsible for creating and destroying resources

// Engine defines an interface for the Shipyard engine
// Engine defines an interface for the Jumppad engine
//
//go:generate mockery --name Engine --filename engine.go
type Engine interface {
Expand All @@ -46,7 +46,7 @@ type EngineImpl struct {
config *hclconfig.Config
}

// New creates a new shipyard engine
// New creates a new Jumppad engine
func New(p config.Providers, l logger.Logger) (Engine, error) {
e := &EngineImpl{}
e.log = l
Expand All @@ -63,14 +63,14 @@ func (e *EngineImpl) Config() *hclconfig.Config {
return e.config
}

// ParseConfig parses the given Shipyard files and creating the resource types but does
// ParseConfig parses the given Jumppad files and creating the resource types but does
// not apply or destroy the resources.
// This function can be used to check the validity of a configuration without making changes
func (e *EngineImpl) ParseConfig(path string) (*hclconfig.Config, error) {
return e.ParseConfigWithVariables(path, nil, "")
}

// ParseConfigWithVariables parses the given Shipyard files and creating the resource types but does
// ParseConfigWithVariables parses the given Jumppad files and creating the resource types but does
// not apply or destroy the resources.
// This function can be used to check the validity of a configuration without making changes
func (e *EngineImpl) ParseConfigWithVariables(path string, vars map[string]string, variablesFile string) (*hclconfig.Config, error) {
Expand Down
25 changes: 23 additions & 2 deletions pkg/jumppad/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jumppad
import (
"fmt"
"log"
"os"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -398,7 +399,7 @@ func TestParseConfig(t *testing.T) {

require.Len(t, r.Resources, 6)

// should not have crated any providers
// should not have created any providers
testAssertMethodCalled(t, mp, "Create", 0)
testAssertMethodCalled(t, mp, "Destroy", 0)
}
Expand All @@ -411,7 +412,27 @@ func TestParseWithVariables(t *testing.T) {

require.Len(t, r.Resources, 6)

// should not have crated any providers
// should not have created any providers
testAssertMethodCalled(t, mp, "Create", 0)
testAssertMethodCalled(t, mp, "Destroy", 0)

c, err := e.config.FindResource("resource.container.consul")
require.NoError(t, err)
require.Equal(t, "consul:1.8.1", c.(*container.Container).Image.Name)
}

func TestParseWithEnvironmentVariables(t *testing.T) {
e, mp := setupTests(t, nil)

err := os.Setenv("JUMPPAD_VAR_version", "consul:1.8.1")
require.NoError(t, err)

r, err := e.ParseConfig("../../examples/single_file/container.hcl")
require.NoError(t, err)

require.Len(t, r.Resources, 6)

// should not have created any providers
testAssertMethodCalled(t, mp, "Create", 0)
testAssertMethodCalled(t, mp, "Destroy", 0)

Expand Down
Loading