package client import ( "testing" "github.com/jaypipes/ghw/pkg/block" "github.com/kairos-io/kairos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) func TestClient(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Discovery Client Suite") } var _ = Describe("Flow Detection", func() { var client *Client BeforeEach(func() { // Create a test client with basic config and logger client = &Client{} client.Config.Kcrypt.Challenger.Server = "http://test-server.local" client.Logger = types.NewKairosLogger("test-client", "debug", false) }) Context("TPM attestation capabilities", func() { It("should detect TPM flow availability", func() { canUseTPM := client.canUseTPMAttestation() // Log the result for manual verification if canUseTPM { GinkgoLogr.Info("TPM attestation flow will be used") } else { GinkgoLogr.Info("Legacy flow will be used (no TPM or empty PCRs)") } // The test doesn't assert anything specific since TPM availability depends on the environment // This is more of an integration test to verify the flow selection logic works Expect(canUseTPM).To(BeAssignableToTypeOf(bool(true))) }) }) Context("Logging functionality", func() { It("should have a valid logger", func() { // Test that client has a valid logger Expect(client.Logger).NotTo(BeNil()) // Test debug logging works without error client.Logger.Debugf("Test log entry for flow detection") // If we get here without panic, logging is working Expect(true).To(BeTrue()) }) }) Context("Flow routing", func() { It("should call the appropriate flow based on TPM availability", func() { // This test verifies that waitPass correctly routes to either TPM or legacy flow // Since we don't have a real server, we expect an error, but the routing logic should work _, err := client.waitPass(&block.Partition{ Name: "test-partition", UUID: "test-uuid", FilesystemLabel: "test-label", }, 1) // We expect an error since there's no real server, but the flow selection should work Expect(err).To(HaveOccurred()) // The flow routing logic now uses the logger instead of the file, // so we just verify the error occurred as expected Expect(err.Error()).To(ContainSubstring("TPM attestation flow not implemented yet")) }) }) })