-
Notifications
You must be signed in to change notification settings - Fork 25
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 #187 from suborbital/issue-123
feat(builder): Introduce templating for prereq commands
- Loading branch information
Showing
5 changed files
with
112 additions
and
8 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,68 @@ | ||
package context | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/suborbital/atmo/directive" | ||
) | ||
|
||
func TestPrereq_GetCommand(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
prereq Prereq | ||
r RunnableDir | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "successfully expands template", | ||
prereq: Prereq{ | ||
File: "_lib/_lib.tar.gz", | ||
Command: "curl -L https://github.com/suborbital/reactr/archive/v{{ .Runnable.APIVersion }}.tar.gz -o _lib/_lib.tar.gz", | ||
}, | ||
r: RunnableDir{ | ||
Runnable: &directive.Runnable{ | ||
APIVersion: "0.33.75", | ||
}, | ||
}, | ||
want: "curl -L https://github.com/suborbital/reactr/archive/v0.33.75.tar.gz -o _lib/_lib.tar.gz", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "errors due to missing data to expand with", | ||
prereq: Prereq{ | ||
File: "_lib/_lib.tar.gz", | ||
Command: "curl -L https://github.com/suborbital/reactr/archive/v{{ .Runnable.APIVersion }}.tar.gz -o _lib/_lib.tar.gz", | ||
}, | ||
r: RunnableDir{ | ||
Runnable: nil, | ||
}, | ||
want: "", | ||
wantErr: assert.Error, | ||
}, | ||
{ | ||
name: "successfully expands command with no template tag in it", | ||
prereq: Prereq{ | ||
File: "_lib/_lib.tar.gz", | ||
Command: "curl -L https://github.com/suborbital/reactr/archive/v2.tar.gz -o _lib/_lib.tar.gz", | ||
}, | ||
r: RunnableDir{ | ||
Runnable: &directive.Runnable{ | ||
APIVersion: "0.33.75", | ||
}, | ||
}, | ||
want: "curl -L https://github.com/suborbital/reactr/archive/v2.tar.gz -o _lib/_lib.tar.gz", | ||
wantErr: assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := tt.prereq.GetCommand(tt.r) | ||
|
||
tt.wantErr(t, err) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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