package main import ( "context" "encoding/json" "sync" "testing" "git.novox.be/novox/mesh-sdk/go/provider" ) // bucketBus is the helper's bus over in-memory buckets. type bucketBus struct { mu sync.Mutex buckets map[string]map[string][]byte } func (b *bucketBus) Watch(_ context.Context, bucket string, handle func(string, []byte)) error { b.mu.Lock() defer b.mu.Unlock() for k, v := range b.buckets[bucket] { handle(k, v) } return nil } func (b *bucketBus) Put(_ context.Context, bucket, key string, value []byte) error { b.mu.Lock() defer b.mu.Unlock() if b.buckets[bucket] == nil { b.buckets[bucket] = map[string][]byte{} } b.buckets[bucket][key] = append([]byte(nil), value...) return nil } func (b *bucketBus) Delete(_ context.Context, bucket, key string) error { b.mu.Lock() defer b.mu.Unlock() delete(b.buckets[bucket], key) return nil } // A consumer of a route is answered with the names its plan's entry carries, and nothing of a credential (issue 792): // the entry's values are the controller's composition, copied unchanged, and no vault is asked. func TestAConsumerOfARouteIsToldItsNamesFromItsPlanEntry(t *testing.T) { bus := &bucketBus{buckets: map[string]map[string][]byte{}} plan, _ := json.Marshal(map[string]any{"node": "g14", "module": "gitea", "provisioning": map[string]any{ "provisions": []any{map[string]any{"provision": ProvisionName, "provider": "novox", "provider-module": ModuleName, "at": "10.7.0.1", "from": "novox", "as": "mesh_g14_gitea", "names": map[string]any{"name": "git.example.org", "internal-name": "git.novox.internal", "name-web": "git.example.org"}}}}}) if err := bus.Put(context.Background(), provider.AssignmentsBucket, "g14.gitea", plan); err != nil { t.Fatal(err) } p := newProvider("novox", bus, t.Logf) out, err := p.Pass(context.Background()) if err != nil { t.Fatal(err) } if len(out) != 1 || out[0].Status != provider.Answered { t.Fatalf("the pass did %+v", out) } var e provider.Entry if err := json.Unmarshal(bus.buckets[provider.BucketOf(ModuleName)]["g14.gitea.route"], &e); err != nil { t.Fatal(err) } if e.Values["name-web"] != "git.example.org" || e.Values["name"] != "git.example.org" || e.Values["internal-name"] != "git.novox.internal" || e.VaultName != "" || e.User != "" || e.Refused != "" { t.Fatalf("the entry is %+v", e) } }