2019-04-08 07:38:55 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-10-31 10:49:34 -04:00
|
|
|
if p.Duration != time.Second {
|
2019-04-08 07:38:55 -04:00
|
|
|
t.Fatal("wrong duration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvisioner_Provision(t *testing.T) {
|
|
|
|
ctxCancelled, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
type fields struct {
|
2019-10-31 10:49:34 -04:00
|
|
|
Duration time.Duration
|
2019-04-08 07:38:55 -04:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
2019-10-31 10:49:34 -04:00
|
|
|
{"valid sleep", fields{1 * time.Millisecond}, args{context.Background()}, false},
|
|
|
|
{"timeout", fields{1 * time.Millisecond}, args{ctxCancelled}, true},
|
2019-04-08 07:38:55 -04:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
p := &Provisioner{
|
|
|
|
Duration: tt.fields.Duration,
|
|
|
|
}
|
2019-12-12 18:47:17 -05:00
|
|
|
if err := p.Provision(tt.args.ctx, nil, nil, make(map[string]interface{})); (err != nil) != tt.wantErr {
|
2019-04-08 07:38:55 -04:00
|
|
|
t.Errorf("Provisioner.Provision() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|