mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-20 23:11:40 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package sleep
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func test1sConfig() map[string]interface{} {
|
|
return map[string]interface{}{
|
|
"duration": "1s",
|
|
}
|
|
}
|
|
|
|
func TestConfigPrepare_1s(t *testing.T) {
|
|
raw := test1sConfig()
|
|
var p Provisioner
|
|
err := p.Prepare(raw)
|
|
if err != nil {
|
|
t.Fatalf("prerare failed: %v", err)
|
|
}
|
|
|
|
if p.Duration != time.Second {
|
|
t.Fatal("wrong duration")
|
|
}
|
|
}
|
|
|
|
func TestProvisioner_Provision(t *testing.T) {
|
|
ctxCancelled, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
type fields struct {
|
|
Duration time.Duration
|
|
}
|
|
type args struct {
|
|
ctx context.Context
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{"valid sleep", fields{1 * time.Millisecond}, args{context.Background()}, false},
|
|
{"timeout", fields{1 * time.Millisecond}, args{ctxCancelled}, true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := &Provisioner{
|
|
Duration: tt.fields.Duration,
|
|
}
|
|
if err := p.Provision(tt.args.ctx, nil, nil, make(map[string]interface{})); (err != nil) != tt.wantErr {
|
|
t.Errorf("Provisioner.Provision() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|