Skip to content

Commit

Permalink
tests,examples: add explicit version field
Browse files Browse the repository at this point in the history
  • Loading branch information
chrboe committed Mar 27, 2023
1 parent 898964d commit c147bc3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/provisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ $ virter vm exec my-vm -p examples/hello-world/hello-world.toml --set values.Ima

## Example
```
version = 1
[values]
Image = "virter-hello-text"
Expand Down
2 changes: 2 additions & 0 deletions examples/hello-world-docker/hello-world-docker.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = 1

[values]
Image = "virter-hello-world"

Expand Down
2 changes: 2 additions & 0 deletions examples/hello-world/hello-world.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = 1

[[steps]]
[steps.shell]
script = '''
Expand Down
22 changes: 19 additions & 3 deletions internal/virter/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

func TestNewProvisionConfig(t *testing.T) {
validGlobalOnly := `
version = 1
[env]
foo="bar"
bar="baz"
Expand All @@ -22,6 +24,8 @@ script = "echo rck"
`

validLocalOnly := `
version = 1
[[steps]]
[steps.shell]
script = "echo rck"
Expand All @@ -31,6 +35,8 @@ bar="baz=lala"
`

bothDistinct := `
version = 1
[env]
foo="bar"
bar="baz"
Expand All @@ -44,6 +50,8 @@ here=""
`

bothOverride := `
version = 1
[env]
foo="bar"
bar="baz"
Expand All @@ -56,7 +64,7 @@ rck="was"
foo="rck"
`

// IMPORTANT: this asumes 1 shell step!
// IMPORTANT: this assumes 1 shell step!
tests := []struct {
input string
valid bool
Expand All @@ -67,10 +75,10 @@ foo="rck"
{validLocalOnly, true, ProvisionOption{Overrides: []string{}}, []string{"foo=bar", "bar=baz=lala"}},
{bothDistinct, true, ProvisionOption{Overrides: []string{}}, []string{"foo=bar", "bar=baz", "rck=was", "here="}},
{bothOverride, true, ProvisionOption{Overrides: []string{}}, []string{"foo=rck", "bar=baz", "rck=was"}},
{"", true, ProvisionOption{
{"version = 1", true, ProvisionOption{
Overrides: []string{"steps[0].shell.script=env", "steps[0].shell.env.foo=bar"},
}, []string{"foo=bar"}},
{"", true, ProvisionOption{
{"version = 1", true, ProvisionOption{
Overrides: []string{"steps[0].shell.script=env", "env.foo=bar", "steps[0].shell.env.foo=rck"},
}, []string{"foo=rck"}},
{bothOverride, true, ProvisionOption{
Expand Down Expand Up @@ -121,6 +129,8 @@ func envEqual(env, expected []string) bool {

func TestNewProvisionConfigTemplate(t *testing.T) {
noTemplate := `
version = 1
[[steps]]
[steps.container]
image = "some-image"
Expand All @@ -141,6 +151,8 @@ dest = "some-dest"
`

allTemplate := `
version = 1
[values]
ShellEnv = "default-value"
Expand All @@ -165,6 +177,8 @@ dest = "some-dest"
`

globalEnvTemplate := `
version = 1
[env]
foo = "{{.Env}}"
blah = "{{.MoreEnv}}"
Expand All @@ -177,6 +191,8 @@ foo = "bar"
`

brokenTemplate := `
version = 1
[[steps]]
[steps.shell]
script = "echo jrc"
Expand Down
2 changes: 2 additions & 0 deletions tests/provision.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = 1

[[steps]]
[steps.shell]
script = """
Expand Down
2 changes: 2 additions & 0 deletions tests/test-run.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = 1

[values]
ContainerImage = "ssh"

Expand Down

0 comments on commit c147bc3

Please sign in to comment.