From 3e479b2d50824678151483937f8480e9d4c3999a Mon Sep 17 00:00:00 2001 From: pauhull Date: Tue, 7 Nov 2023 09:51:31 +0100 Subject: [PATCH] test: extend certificate test cases --- internal/cmd/certificate/create_test.go | 34 +++++++++++++++++++++- internal/cmd/certificate/describe_test.go | 12 ++++++++ internal/cmd/certificate/testdata/cert.pem | 1 + internal/cmd/certificate/testdata/key.pem | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 internal/cmd/certificate/testdata/cert.pem create mode 100644 internal/cmd/certificate/testdata/key.pem diff --git a/internal/cmd/certificate/create_test.go b/internal/cmd/certificate/create_test.go index ea69b51f..f5bc8dd2 100644 --- a/internal/cmd/certificate/create_test.go +++ b/internal/cmd/certificate/create_test.go @@ -11,7 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -func TestCreate(t *testing.T) { +func TestCreateManaged(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() @@ -47,3 +47,35 @@ func TestCreate(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expOut, out) } + +func TestCreateUploaded(t *testing.T) { + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := CreateCmd.CobraCommand( + context.Background(), + fx.Client, + fx.TokenEnsurer, + fx.ActionWaiter) + fx.ExpectEnsureToken() + + fx.Client.CertificateClient.EXPECT(). + Create(gomock.Any(), hcloud.CertificateCreateOpts{ + Name: "test", + Type: hcloud.CertificateTypeUploaded, + Certificate: "certificate file content", + PrivateKey: "key file content", + }). + Return(&hcloud.Certificate{ + ID: 123, + Name: "test", + Type: hcloud.CertificateTypeUploaded, + }, nil, nil) + + out, err := fx.Run(cmd, []string{"--name", "test", "--key-file", "testdata/key.pem", "--cert-file", "testdata/cert.pem"}) + + expOut := "Certificate 123 created\n" + + assert.NoError(t, err) + assert.Equal(t, expOut, out) +} diff --git a/internal/cmd/certificate/describe_test.go b/internal/cmd/certificate/describe_test.go index c6e077bb..96ca809d 100644 --- a/internal/cmd/certificate/describe_test.go +++ b/internal/cmd/certificate/describe_test.go @@ -40,6 +40,14 @@ func TestDescribe(t *testing.T) { ID: 123, Type: hcloud.CertificateUsedByRefTypeLoadBalancer, }}, + Status: &hcloud.CertificateStatus{ + Error: &hcloud.Error{ + Code: hcloud.ErrorCode("cert_error"), + Message: "Certificate error", + }, + Issuance: hcloud.CertificateStatusTypeFailed, + Renewal: hcloud.CertificateStatusTypeScheduled, + }, } fx.Client.CertificateClient.EXPECT(). @@ -58,6 +66,10 @@ Fingerprint: Created: %s (%s) Not valid before: %s (%s) Not valid after: %s (%s) +Status: + Issuance: failed + Renewal: scheduled + Failure reason: Certificate error Domain names: - example.com Labels: diff --git a/internal/cmd/certificate/testdata/cert.pem b/internal/cmd/certificate/testdata/cert.pem new file mode 100644 index 00000000..9d2a42fa --- /dev/null +++ b/internal/cmd/certificate/testdata/cert.pem @@ -0,0 +1 @@ +certificate file content \ No newline at end of file diff --git a/internal/cmd/certificate/testdata/key.pem b/internal/cmd/certificate/testdata/key.pem new file mode 100644 index 00000000..2a7b7760 --- /dev/null +++ b/internal/cmd/certificate/testdata/key.pem @@ -0,0 +1 @@ +key file content \ No newline at end of file