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
ddbc145d
Commit
ddbc145d
authored
Jun 16, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented acceptance test for compress
parent
f5067e97
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
15 deletions
+88
-15
post-processor/compress/post-processor_test.go
post-processor/compress/post-processor_test.go
+88
-15
No files found.
post-processor/compress/post-processor_test.go
View file @
ddbc145d
package
compress
// 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(),
// })
// }
import
(
"fmt"
"os"
"strings"
"testing"
"github.com/mitchellh/packer/builder/file"
env
"github.com/mitchellh/packer/helper/builder/testing"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template"
)
func
setup
(
t
*
testing
.
T
)
(
packer
.
Ui
,
packer
.
Artifact
,
error
)
{
// Create fake UI and Cache
ui
:=
packer
.
TestUi
(
t
)
cache
:=
&
packer
.
FileCache
{
CacheDir
:
os
.
TempDir
()}
// Create config for file builder
const
fileConfig
=
`{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}`
tpl
,
err
:=
template
.
Parse
(
strings
.
NewReader
(
fileConfig
))
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"Unable to parse setup configuration: %s"
,
err
)
}
// Prepare the file builder
builder
:=
file
.
Builder
{}
warnings
,
err
:=
builder
.
Prepare
(
tpl
.
Builders
[
"file"
]
.
Config
)
if
len
(
warnings
)
>
0
{
for
_
,
warn
:=
range
warnings
{
return
nil
,
nil
,
fmt
.
Errorf
(
"Configuration warning: %s"
,
warn
)
}
}
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"Invalid configuration: %s"
,
err
)
}
// Run the file builder
artifact
,
err
:=
builder
.
Run
(
ui
,
nil
,
cache
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"Failed to build artifact: %s"
,
err
)
}
return
ui
,
artifact
,
err
}
func
TestSimpleCompress
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
env
.
TestEnvVar
)
==
""
{
t
.
Skip
(
fmt
.
Sprintf
(
"Acceptance tests skipped unless env '%s' set"
,
env
.
TestEnvVar
))
}
ui
,
artifact
,
err
:=
setup
(
t
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error bootstrapping test: %s"
,
err
)
}
if
artifact
!=
nil
{
defer
artifact
.
Destroy
()
}
tpl
,
err
:=
template
.
Parse
(
strings
.
NewReader
(
simpleTestCase
))
if
err
!=
nil
{
t
.
Fatalf
(
"Unable to parse test config: %s"
,
err
)
}
compressor
:=
PostProcessor
{}
compressor
.
Configure
(
tpl
.
PostProcessors
[
0
][
0
]
.
Config
)
artifactOut
,
_
,
err
:=
compressor
.
PostProcess
(
ui
,
artifact
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to compress artifact: %s"
,
err
)
}
// Cleanup after the test completes
defer
artifactOut
.
Destroy
()
// Verify things look good
fi
,
err
:=
os
.
Stat
(
"package.tar.gz"
)
if
err
!=
nil
{
t
.
Errorf
(
"Unable to read archive: %s"
,
err
)
}
if
fi
.
IsDir
()
{
t
.
Error
(
"Archive should not be a directory"
)
}
}
const
simpleTestCase
=
`
{
"post-processors": [
{
"type": "compress",
"output": "foo.tar.gz"
"output": "package.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