Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
fe0c5486
Commit
fe0c5486
authored
Jun 16, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added acceptance test for file builder
parent
29f02d24
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
19 deletions
+90
-19
builder/file/builder.go
builder/file/builder.go
+1
-15
builder/file/builder_test.go
builder/file/builder_test.go
+67
-0
builder/file/config_test.go
builder/file/config_test.go
+1
-3
builder/file/test-fixtures/artifact.txt
builder/file/test-fixtures/artifact.txt
+1
-0
post-processor/compress/post-processor_test.go
post-processor/compress/post-processor_test.go
+20
-1
No files found.
builder/file/builder.go
View file @
fe0c5486
...
@@ -15,27 +15,13 @@ import (
...
@@ -15,27 +15,13 @@ import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
const
BuilderId
=
"
cbednarski
.file"
const
BuilderId
=
"
packer
.file"
type
Builder
struct
{
type
Builder
struct
{
config
*
Config
config
*
Config
runner
multistep
.
Runner
runner
multistep
.
Runner
}
}
// Prepare is responsible for configuring the builder and validating
// that configuration. Any setup should be done in this method. Note that
// NO side effects should take place in prepare, it is meant as a state
// setup only. Calling Prepare is not necessarilly followed by a Run.
//
// The parameters to Prepare are a set of interface{} values of the
// configuration. These are almost always `map[string]interface{}`
// parsed from a template, but no guarantee is made.
//
// Each of the configuration values should merge into the final
// configuration.
//
// Prepare should return a list of warnings along with any errors
// that occured while preparing.
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
c
,
warnings
,
errs
:=
NewConfig
(
raws
...
)
c
,
warnings
,
errs
:=
NewConfig
(
raws
...
)
if
errs
!=
nil
{
if
errs
!=
nil
{
...
...
builder/file/builder_test.go
View file @
fe0c5486
package
file
package
file
import
(
import
(
"fmt"
"io/ioutil"
"testing"
"testing"
builderT
"github.com/mitchellh/packer/helper/builder/testing"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
func
TestBuilder_implBuilder
(
t
*
testing
.
T
)
{
func
TestBuilder_implBuilder
(
t
*
testing
.
T
)
{
var
_
packer
.
Builder
=
new
(
Builder
)
var
_
packer
.
Builder
=
new
(
Builder
)
}
}
func
TestBuilderFileAcc_content
(
t
*
testing
.
T
)
{
builderT
.
Test
(
t
,
builderT
.
TestCase
{
Builder
:
&
Builder
{},
Template
:
fileContentTest
,
Check
:
checkContent
,
})
}
func
TestBuilderFileAcc_copy
(
t
*
testing
.
T
)
{
builderT
.
Test
(
t
,
builderT
.
TestCase
{
Builder
:
&
Builder
{},
Template
:
fileCopyTest
,
Check
:
checkCopy
,
})
}
func
checkContent
(
artifacts
[]
packer
.
Artifact
)
error
{
content
,
err
:=
ioutil
.
ReadFile
(
"contentTest.txt"
)
if
err
!=
nil
{
return
err
}
contentString
:=
string
(
content
)
if
contentString
!=
"hello world!"
{
return
fmt
.
Errorf
(
"Unexpected file contents: %s"
,
contentString
)
}
return
nil
}
func
checkCopy
(
artifacts
[]
packer
.
Artifact
)
error
{
content
,
err
:=
ioutil
.
ReadFile
(
"copyTest.txt"
)
if
err
!=
nil
{
return
err
}
contentString
:=
string
(
content
)
if
contentString
!=
"Hello world.
\n
"
{
return
fmt
.
Errorf
(
"Unexpected file contents: %s"
,
contentString
)
}
return
nil
}
const
fileContentTest
=
`
{
"builders": [
{
"type":"test",
"target":"contentTest.txt",
"content":"hello world!"
}
]
}
`
const
fileCopyTest
=
`
{
"builders": [
{
"type":"test",
"target":"copyTest.txt",
"source":"test-fixtures/artifact.txt"
}
]
}
`
builder/file/config_test.go
View file @
fe0c5486
package
file
package
file
import
(
import
(
"fmt"
"strings"
"strings"
"testing"
"testing"
)
)
...
@@ -39,8 +38,7 @@ func TestNoContent(t *testing.T) {
...
@@ -39,8 +38,7 @@ func TestNoContent(t *testing.T) {
delete
(
raw
,
"content"
)
delete
(
raw
,
"content"
)
delete
(
raw
,
"source"
)
delete
(
raw
,
"source"
)
_
,
warns
,
_
:=
NewConfig
(
raw
)
_
,
warns
,
_
:=
NewConfig
(
raw
)
fmt
.
Println
(
len
(
warns
))
fmt
.
Printf
(
"%#v
\n
"
,
warns
)
if
len
(
warns
)
==
0
{
if
len
(
warns
)
==
0
{
t
.
Error
(
"Expected config warning without any content"
)
t
.
Error
(
"Expected config warning without any content"
)
}
}
...
...
builder/file/test-fixtures/artifact.txt
0 → 100644
View file @
fe0c5486
Hello world.
post-processor/compress/post-processor_test.go
View file @
fe0c5486
package
compress
package
compress
import
()
// import (
// "testing"
//
// builderT "github.com/mitchellh/packer/helper/builder/testing"
// )
//
// func TestBuilderTagsAcc_basic(t *testing.T) {
// builderT.Test(t, builderT.TestCase{
// Builder: &Builder{},
// Template: simpleTestCase,
// Check: checkTags(),
// })
// }
const
simpleTestCase
=
`
{
"type": "compress",
"output": "foo.tar.gz"
}
`
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment