Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -28,12 +29,22 @@ type call struct {
|
||||
|
||||
type fake struct {
|
||||
answer func(c call) Ran
|
||||
mu sync.Mutex
|
||||
calls []call
|
||||
}
|
||||
|
||||
// recorded returns a copy of the calls so far; scans call run from parallel goroutines.
|
||||
func (f *fake) recorded() []call {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
return append([]call(nil), f.calls...)
|
||||
}
|
||||
|
||||
func (f *fake) run(_ context.Context, env []string, name string, args ...string) Ran {
|
||||
c := call{env, name, args}
|
||||
f.mu.Lock()
|
||||
f.calls = append(f.calls, c)
|
||||
f.mu.Unlock()
|
||||
if f.answer == nil {
|
||||
return Ran{Status: 1}
|
||||
}
|
||||
@@ -152,7 +163,7 @@ func TestKeysAreDescribedByTheirPublicHalfAndAPassphraseIsAskedNotRead(t *testin
|
||||
if k := by["stray"]; !k.PublicMissing || k.OfferedBy != "" || k.Fingerprint != edFP {
|
||||
t.Errorf("stray: %+v", k)
|
||||
}
|
||||
for _, c := range f.calls {
|
||||
for _, c := range f.recorded() {
|
||||
if c.name == "ssh-keygen" && c.args[0] == "-y" && !reflect.DeepEqual(c.args[:3], []string{"-y", "-P", ""}) {
|
||||
t.Errorf("a passphrase check could prompt: %v", c.args)
|
||||
}
|
||||
@@ -263,7 +274,7 @@ func TestKnownHostComparesWhatIsKnownWithWhatIsOffered(t *testing.T) {
|
||||
t.Fatalf("not appended: %s", after)
|
||||
}
|
||||
sawRemove := false
|
||||
for _, c := range f.calls {
|
||||
for _, c := range f.recorded() {
|
||||
if c.name == "ssh-keygen" && reflect.DeepEqual(c.args[:2], []string{"-R", "ace.internal"}) {
|
||||
sawRemove = true
|
||||
}
|
||||
@@ -303,7 +314,7 @@ func TestTestSaysHowItAuthenticatedOrWhyNot(t *testing.T) {
|
||||
if err != nil || got["ok"] != true || got["method"] != "publickey" || got["connected_to"] != "10.0.0.2:22" {
|
||||
t.Fatalf("%v %v", got, err)
|
||||
}
|
||||
args := strings.Join(f.calls[0].args, " ")
|
||||
args := strings.Join(f.recorded()[0].args, " ")
|
||||
if !strings.Contains(args, "BatchMode=yes") || !strings.Contains(args, "StrictHostKeyChecking=yes") || !strings.HasSuffix(args, "ace true") {
|
||||
t.Fatalf("not a batch test: %s", args)
|
||||
}
|
||||
@@ -388,7 +399,7 @@ func TestTheManifestsRegionIsWhatSshReads(t *testing.T) {
|
||||
var region string
|
||||
for _, r := range m.Resources {
|
||||
if r["id"] == "config" {
|
||||
region = r["content"].(string)
|
||||
region = templateText(t, r)
|
||||
if r["into"] != "block" || r["at"] != "start" {
|
||||
t.Fatalf("the region is not written into the start: %v", r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user