Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: refactored the tests

=8011e06410df
diff --git a/tests/cmd/fakenet/main.go b/tests/cmd/fakenet/main.go
index 6c64252788..84489bf5e0 100644
--- a/tests/cmd/fakenet/main.go
+++ b/tests/cmd/fakenet/main.go
@@ -9,6 +9,7 @@
package main
import (
+ "crypto/tls"
"log"
"net/http"
"os"
@@ -46,7 +47,7 @@ func main() {
log.Fatalf("fakenet: admin listener: %v", http.ListenAndServe(":8080", srv.Admin(ca)))
}()
- ln, err := tlsListen(":443", ca)
+ ln, err := tls.Listen("tcp", ":443", ca.TLSConfig())
if err != nil {
log.Fatalf("fakenet: %v", err)
}
diff --git a/tests/cmd/fakenet/tls.go b/tests/cmd/fakenet/tls.go
deleted file mode 100644
index 7b6881b99d..0000000000
--- a/tests/cmd/fakenet/tls.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package main
-
-import (
- "crypto/tls"
- "net"
-
- "github.com/Infisical/infisical/tests/infra/fakenet"
-)
-
-func tlsListen(addr string, ca *fakenet.CA) (net.Listener, error) {
- return tls.Listen("tcp", addr, ca.TLSConfig())
-}
diff --git a/tests/fakes/smtp/controlplane.go b/tests/fakes/smtp/controlplane.go
index da1744ab18..a37ee76ef9 100644
--- a/tests/fakes/smtp/controlplane.go
+++ b/tests/fakes/smtp/controlplane.go
@@ -43,7 +43,7 @@ func (in *Inbox) Expect(tt *testing.T, addr string, filters ...Filter) Message {
"Reading another tenant's mail would make the test order-dependent; use tn.Email(local)",
in.domain, addr)
}
- return in.ExpectEvent[MessageReceived](tt, func(e MessageReceived) bool {
+ received := in.ExpectEvent[MessageReceived](tt, func(e MessageReceived) bool {
if e.Recipient != addr {
return false
}
@@ -53,5 +53,6 @@ func (in *Inbox) Expect(tt *testing.T, addr string, filters ...Filter) Message {
}
}
return true
- }).Message
+ })
+ return received.Message
}
diff --git a/tests/infra/fakenet/events_test.go b/tests/infra/fakenet/events_test.go
index 3da6bf19e3..4ac6a13c9b 100644
--- a/tests/infra/fakenet/events_test.go
+++ b/tests/infra/fakenet/events_test.go
@@ -248,29 +248,43 @@ func TestEvents_ExpectNo(t *testing.T) {
}
func TestEvents_Failure(t *testing.T) {
- cases := []struct {
- name string
- do func(r *rig, t *testing.T)
- want string
- }{
- {"should say nothing arrived when the scope is empty", func(*rig, *testing.T) {}, "no events arrived in this scope"},
- {"should list other events when only a different type arrived", func(r *rig, t *testing.T) { r.call(t, http.MethodDelete, "f-a", "X") }, "no items.item-created arrived"},
- {"should list near misses when the predicate rejected them", func(r *rig, t *testing.T) { r.call(t, http.MethodPost, "f-a", "WRONG") }, "none matched"},
- }
- for _, tc := range cases {
- t.Run(tc.name, func(t *testing.T) {
- // Setup
- r := newRig(t, "f")
- sc := r.scope(t, "f-a")
- tc.do(r, t)
-
- // Action
- err := expectErr(t, sc, nameIs[ItemCreated]("RIGHT"), Within(500*time.Millisecond))
-
- // Assert
- require.ErrorContains(t, err, tc.want)
- })
- }
+ t.Run("should say nothing arrived when the scope is empty", func(t *testing.T) {
+ // Setup
+ r := newRig(t, "f1")
+ sc := r.scope(t, "f1-a")
+
+ // Action
+ err := expectErr(t, sc, nameIs[ItemCreated]("RIGHT"), Within(500*time.Millisecond))
+
+ // Assert
+ require.ErrorContains(t, err, "no events arrived in this scope")
+ })
+
+ t.Run("should list other events when only a different type arrived", func(t *testing.T) {
+ // Setup
+ r := newRig(t, "f2")
+ sc := r.scope(t, "f2-a")
+ r.call(t, http.MethodDelete, "f2-a", "X")
+
+ // Action
+ err := expectErr(t, sc, nameIs[ItemCreated]("RIGHT"), Within(500*time.Millisecond))
+
+ // Assert
+ require.ErrorContains(t, err, "no items.item-created arrived")
+ })
+
+ t.Run("should list near misses when the predicate rejected them", func(t *testing.T) {
+ // Setup
+ r := newRig(t, "f3")
+ sc := r.scope(t, "f3-a")
+ r.call(t, http.MethodPost, "f3-a", "WRONG")
+
+ // Action
+ err := expectErr(t, sc, nameIs[ItemCreated]("RIGHT"), Within(500*time.Millisecond))
+
+ // Assert
+ require.ErrorContains(t, err, "none matched")
+ })
}
func TestEvents_Loss(t *testing.T) {
diff --git a/tests/infra/module.go b/tests/infra/module.go
index 67ab7319de..967f3c6788 100644
--- a/tests/infra/module.go
+++ b/tests/infra/module.go
@@ -141,9 +141,9 @@ func Resolve(modules []Module, scopes map[ModuleKey]Scope) (Plan, error) {
}
// checkLifetimes rejects a module that depends on something shorter lived than
-// itself. This is not hypothetical: a Shared Infisical takes HTTP_PROXY at container
-// start, so pointing it at a Package-scoped WireMock breaks every other package the
-// moment that one finishes.
+// itself. A Shared Infisical takes fakenet's address and CA when its container is
+// created, so if fakenet were Package-scoped it would vanish when that package
+// finished and break every other package still using the instance.
func checkLifetimes(m Module, scopes map[ModuleKey]Scope, byKey map[ModuleKey]Module) error {
mine, ok := scopes[m.Key()]
if !ok {