Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: zachaller <[email protected]>
  • Loading branch information
zachaller committed Apr 27, 2023
1 parent 798d8c5 commit 35e21aa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions analysis/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package analysis
import (
"context"
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -317,6 +318,44 @@ func TestNoReconcileForAnalysisRunWithDeletionTimestamp(t *testing.T) {
f.run(getKey(ar, t))
}

func TestFailedToCreateProviderError(t *testing.T) {
f := newFixture(t)
defer f.Close()

ar := &v1alpha1.AnalysisRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
Metrics: []v1alpha1.Metric{
{
Name: "metric1",
Provider: v1alpha1.MetricProvider{
Plugin: map[string]json.RawMessage{"mypluginns/myplugin": []byte(`{"invalid": "json"}`)},
},
},
},
},
}
f.analysisRunLister = append(f.analysisRunLister, ar)
f.objects = append(f.objects, ar)

c, i, k8sI := f.newController(noResyncPeriodFunc)
c.newProvider = func(logCtx log.Entry, metric v1alpha1.Metric) (metric.Provider, error) {
return nil, fmt.Errorf("failed to create provider")
}

pi := f.expectPatchAnalysisRunAction(ar)

f.runController(getKey(ar, t), true, false, c, i, k8sI)

updatedAr := f.getPatchedAnalysisRun(pi)

assert.Equal(t, v1alpha1.AnalysisPhaseError, updatedAr.Status.MetricResults[0].Measurements[0].Phase)
assert.Equal(t, "failed to create provider", updatedAr.Status.MetricResults[0].Measurements[0].Message)
}

func TestRun(t *testing.T) {
f := newFixture(t)
defer f.Close()
Expand Down

0 comments on commit 35e21aa

Please sign in to comment.