Hi. I’m trying to write a test for generating keys...
# golang
b
Hi. I’m trying to write a test for generating keys with the
tls.NewPrivateKey
method from the github.com/pulumi/pulumi-tls/sdk/v4/go/tls package. The code generates keys outside of a test but not in it. Is this not the correct way to do it:
Copy code
func TestGenerateSSHKey(t *testing.T) {
	config := map[string]string{}

	err := pulumi.RunErr(func(ctx *pulumi.Context) error {

		pulumiKey, err := tls.NewPrivateKey(ctx, "private-key", &tls.PrivateKeyArgs{
			Algorithm:  pulumi.String("ECDSA"),
			EcdsaCurve: pulumi.String("P521"),
		})

		if err != nil {
			t.Logf("Error generating SSH key: %s\n", err)
			return err
		}

		pulumi.All(pulumiKey.PrivateKeyOpenssh).ApplyT(func(args []interface{}) interface{} {

			pKey := args[0]

			t.Logf("Private key: %s\n", pKey)
			if pKey == "" {
				t.Log("Error generating SSH key: private key is empty")
				t.Fail()
			}

			return pKey
		})

		return nil
	}, WithMocksAndConfig("opp-notary-composer", "opp-notary-composer-dev", config, mocks(0)))

	if err != nil {
		t.Log(err)
		t.Fail()
	}
}
I’ve looked through the unit testing and integration testing docs but haven’t been able to figure it out. Would appreciate if there were docs/examples to look at. Thanks. 🙏🏼