Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/carlosframework/platform/internal/registry" |
| 10 | ) |
| 11 | |
| 12 | func TestInstanceRegistryHostAppReusesClaimRegistry(t *testing.T) { |
| 13 | reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | defer reg.Close() |
| 18 | if err := reg.Upsert(registry.Route{Host: "blog.example.com", Kind: "instance", Account: "k7xq", App: "blog"}); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | lookup := instanceRegistryHostApp(reg) |
| 22 | for i := 0; i < 2; i++ { |
| 23 | acct, app, err := lookup("blog.example.com") |
| 24 | if err != nil || acct != "k7xq" || app != "blog" { |
| 25 | t.Fatalf("lookup = %q %q %v", acct, app, err) |
| 26 | } |
| 27 | } |
| 28 | if _, _, err := lookup("unknown.example.com"); !errors.Is(err, os.ErrNotExist) { |
| 29 | t.Fatalf("unknown host = %v", err) |
| 30 | } |
| 31 | if _, err := reg.List(); err != nil { |
| 32 | t.Fatalf("lookup closed shared registry: %v", err) |
| 33 | } |
| 34 | } |
| 35 | |