fix missing error return (#11)

pull/4881/head
Brett Jones 4 years ago committed by GitHub
parent bc7f7b5cef
commit 8e4c3fb6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      internal/handlers/lokistack_create.go
  2. 25
      internal/handlers/lokistack_create_test.go

@ -3,6 +3,7 @@ package handlers
import (
"context"
"github.com/ViaQ/logerr/kverrors"
"github.com/ViaQ/logerr/log"
lokiv1beta1 "github.com/ViaQ/loki-operator/api/v1beta1"
"github.com/ViaQ/loki-operator/internal/external/k8s"
@ -25,6 +26,7 @@ func CreateLokiStack(ctx context.Context, req ctrl.Request, k k8s.Client) error
ll.Error(err, "could not find the requested loki stack", "name", req.NamespacedName)
return nil
}
return kverrors.Wrap(err, "failed to lookup lokistack", "name", req.NamespacedName)
}
// Here we will translate the lokiv1beta1.LokiStack options into manifest options

@ -2,6 +2,7 @@ package handlers_test
import (
"context"
"errors"
"flag"
"io/ioutil"
"os"
@ -60,6 +61,30 @@ func TestCreateLokiStack_WhenGetReturnsNotFound_DoesNotError(t *testing.T) {
require.Zero(t, k.CreateCallCount())
}
func TestCreateLokiStack_WhenGetReturnsAnErrorOtherThanNotFound_ReturnsTheError(t *testing.T) {
k := &k8sfakes.FakeClient{}
r := ctrl.Request{
NamespacedName: types.NamespacedName{
Name: "my-stack",
Namespace: "some-ns",
},
}
badRequestErr := apierrors.NewBadRequest("you do not belong here")
k.GetStub = func(ctx context.Context, name types.NamespacedName, object client.Object) error {
return badRequestErr
}
err := handlers.CreateLokiStack(context.TODO(), r, k)
require.Equal(t, badRequestErr, errors.Unwrap(err))
// make sure create was NOT called because the Get failed
require.Zero(t, k.CreateCallCount())
}
func TestCreateLokiStack_SetsNamespaceOnAllObjects(t *testing.T) {
k := &k8sfakes.FakeClient{}
r := ctrl.Request{

Loading…
Cancel
Save