2013-05-03 18:49:15 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
"bytes"
|
2018-09-06 10:15:09 -04:00
|
|
|
"io"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
"io/ioutil"
|
2013-08-12 13:25:56 -04:00
|
|
|
"reflect"
|
2013-05-03 18:49:15 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testUi struct {
|
2018-09-06 10:15:09 -04:00
|
|
|
askCalled bool
|
|
|
|
askQuery string
|
|
|
|
errorCalled bool
|
|
|
|
errorMessage string
|
|
|
|
machineCalled bool
|
|
|
|
machineType string
|
|
|
|
machineArgs []string
|
|
|
|
messageCalled bool
|
|
|
|
messageMessage string
|
|
|
|
sayCalled bool
|
|
|
|
sayMessage string
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
trackProgressCalled bool
|
|
|
|
progressBarAddCalled bool
|
|
|
|
progressBarCloseCalled bool
|
2013-05-03 18:49:15 -04:00
|
|
|
}
|
|
|
|
|
2013-06-15 21:24:38 -04:00
|
|
|
func (u *testUi) Ask(query string) (string, error) {
|
2013-06-14 18:17:03 -04:00
|
|
|
u.askCalled = true
|
|
|
|
u.askQuery = query
|
2013-06-15 21:24:38 -04:00
|
|
|
return "foo", nil
|
2013-06-14 18:17:03 -04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *testUi) Error(message string) {
|
2013-05-08 18:12:48 -04:00
|
|
|
u.errorCalled = true
|
2013-05-27 18:12:48 -04:00
|
|
|
u.errorMessage = message
|
2013-05-08 18:12:48 -04:00
|
|
|
}
|
|
|
|
|
2013-08-11 21:16:00 -04:00
|
|
|
func (u *testUi) Machine(t string, args ...string) {
|
|
|
|
u.machineCalled = true
|
|
|
|
u.machineType = t
|
|
|
|
u.machineArgs = args
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:30:38 -04:00
|
|
|
func (u *testUi) Message(message string) {
|
|
|
|
u.messageCalled = true
|
|
|
|
u.messageMessage = message
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *testUi) Say(message string) {
|
2013-05-03 18:49:15 -04:00
|
|
|
u.sayCalled = true
|
2013-05-27 18:12:48 -04:00
|
|
|
u.sayMessage = message
|
2013-05-03 18:49:15 -04:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
func (u *testUi) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) (body io.ReadCloser) {
|
|
|
|
u.trackProgressCalled = true
|
|
|
|
|
|
|
|
return &readCloser{
|
|
|
|
read: func(p []byte) (int, error) {
|
|
|
|
u.progressBarAddCalled = true
|
|
|
|
return stream.Read(p)
|
|
|
|
},
|
|
|
|
close: func() error {
|
|
|
|
u.progressBarCloseCalled = true
|
|
|
|
return stream.Close()
|
|
|
|
},
|
|
|
|
}
|
2018-09-06 10:15:09 -04:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
type readCloser struct {
|
|
|
|
read func([]byte) (int, error)
|
|
|
|
close func() error
|
2018-09-06 10:15:09 -04:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
func (c *readCloser) Close() error { return c.close() }
|
|
|
|
func (c *readCloser) Read(p []byte) (int, error) { return c.read(p) }
|
2018-09-06 09:52:46 -04:00
|
|
|
|
2013-05-03 18:49:15 -04:00
|
|
|
func TestUiRPC(t *testing.T) {
|
|
|
|
// Create the UI to test
|
|
|
|
ui := new(testUi)
|
|
|
|
|
|
|
|
// Start the RPC server
|
2013-12-09 19:22:11 -05:00
|
|
|
client, server := testClientServer(t)
|
|
|
|
defer client.Close()
|
|
|
|
defer server.Close()
|
|
|
|
server.RegisterUi(ui)
|
2013-05-03 18:49:15 -04:00
|
|
|
|
2013-12-09 19:22:11 -05:00
|
|
|
uiClient := client.Ui()
|
2013-05-03 18:49:15 -04:00
|
|
|
|
2013-05-21 14:58:14 -04:00
|
|
|
// Basic error and say tests
|
2013-06-15 21:24:38 -04:00
|
|
|
result, err := uiClient.Ask("query")
|
2013-10-16 23:04:57 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if !ui.askCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
|
|
|
if ui.askQuery != "query" {
|
|
|
|
t.Fatalf("bad: %s", ui.askQuery)
|
|
|
|
}
|
|
|
|
if result != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", result)
|
|
|
|
}
|
2013-06-14 18:17:03 -04:00
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
uiClient.Error("message")
|
2013-10-16 23:04:57 -04:00
|
|
|
if ui.errorMessage != "message" {
|
|
|
|
t.Fatalf("bad: %#v", ui.errorMessage)
|
|
|
|
}
|
2013-05-08 18:12:48 -04:00
|
|
|
|
2013-06-03 14:30:38 -04:00
|
|
|
uiClient.Message("message")
|
2013-10-16 23:04:57 -04:00
|
|
|
if ui.messageMessage != "message" {
|
|
|
|
t.Fatalf("bad: %#v", ui.errorMessage)
|
|
|
|
}
|
2013-06-03 14:30:38 -04:00
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
uiClient.Say("message")
|
2013-10-16 23:04:57 -04:00
|
|
|
if ui.sayMessage != "message" {
|
|
|
|
t.Fatalf("bad: %#v", ui.errorMessage)
|
|
|
|
}
|
2018-09-06 10:15:09 -04:00
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
ctt := []byte("foo bar baz !!!")
|
|
|
|
rc := ioutil.NopCloser(bytes.NewReader(ctt))
|
2018-09-06 10:15:09 -04:00
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
stream := uiClient.TrackProgress("stuff.txt", 0, int64(len(ctt)), rc)
|
|
|
|
if ui.trackProgressCalled != true {
|
|
|
|
t.Errorf("ProgressBastream not called.")
|
2018-09-06 10:15:09 -04:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
b := []byte{0}
|
|
|
|
stream.Read(b) // output ignored
|
2018-09-06 10:15:09 -04:00
|
|
|
if ui.progressBarAddCalled != true {
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
t.Errorf("Add not called.")
|
2018-09-06 10:15:09 -04:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
stream.Close()
|
|
|
|
if ui.progressBarCloseCalled != true {
|
|
|
|
t.Errorf("close not called.")
|
2018-09-06 09:52:46 -04:00
|
|
|
}
|
2013-08-12 13:25:56 -04:00
|
|
|
|
|
|
|
uiClient.Machine("foo", "bar", "baz")
|
|
|
|
if !ui.machineCalled {
|
|
|
|
t.Fatal("machine should be called")
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.machineType != "foo" {
|
|
|
|
t.Fatalf("bad type: %#v", ui.machineType)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []string{"bar", "baz"}
|
|
|
|
if !reflect.DeepEqual(ui.machineArgs, expected) {
|
|
|
|
t.Fatalf("bad: %#v", ui.machineArgs)
|
|
|
|
}
|
2013-05-03 18:49:15 -04:00
|
|
|
}
|