forked from jaegertracing/jaeger-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jaegertracing#42 from IshwarKanse/rebase-bot-main
Merge https://github.com/jaegertracing/jaeger-operator:main (a9770ff) into main
- Loading branch information
Showing
6 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
controllers/elasticsearch/elasticsearch_controller_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package elasticsearch_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
esv1 "github.com/openshift/elasticsearch-operator/apis/logging/v1" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
k8sconfig "sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
k8sreconcile "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
v1 "github.com/jaegertracing/jaeger-operator/apis/v1" | ||
"github.com/jaegertracing/jaeger-operator/controllers/elasticsearch" | ||
) | ||
|
||
func TestElasticSearchSetupWithManager(t *testing.T) { | ||
t.Skip("this test requires a real cluster, otherwise the GetConfigOrDie will die") | ||
|
||
// prepare | ||
mgr, err := manager.New(k8sconfig.GetConfigOrDie(), manager.Options{}) | ||
require.NoError(t, err) | ||
reconciler := elasticsearch.NewReconciler( | ||
k8sClient, | ||
k8sClient, | ||
) | ||
|
||
// test | ||
err = reconciler.SetupWithManager(mgr) | ||
|
||
// verify | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestNewElasticSearchInstance(t *testing.T) { | ||
// prepare | ||
ns := &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-ns", | ||
}, | ||
} | ||
|
||
es := &esv1.Elasticsearch{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-es", | ||
Namespace: "test-ns", | ||
}, | ||
} | ||
|
||
jaeger := v1.NewJaeger(types.NamespacedName{ | ||
Name: "test-jaeger", | ||
Namespace: "test-jaeger", | ||
}) | ||
|
||
esv1.AddToScheme(testScheme) | ||
v1.AddToScheme(testScheme) | ||
|
||
client := fake.NewClientBuilder().WithRuntimeObjects(ns, es, jaeger).Build() | ||
reconciler := elasticsearch.NewReconciler( | ||
client, | ||
client, | ||
) | ||
|
||
req := k8sreconcile.Request{ | ||
NamespacedName: types.NamespacedName{ | ||
Name: "test-es", | ||
Namespace: "test-ns", | ||
}, | ||
} | ||
|
||
_, err := reconciler.Reconcile(context.Background(), req) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package elasticsearch_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
v1 "github.com/jaegertracing/jaeger-operator/apis/v1" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
// +kubebuilder:scaffold:imports | ||
) | ||
|
||
var ( | ||
k8sClient client.Client | ||
testEnv *envtest.Environment | ||
testScheme *runtime.Scheme = scheme.Scheme | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testEnv = &envtest.Environment{ | ||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, | ||
} | ||
|
||
cfg, err := testEnv.Start() | ||
if err != nil { | ||
fmt.Printf("failed to start testEnv: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
if err := v1.AddToScheme(scheme.Scheme); err != nil { | ||
fmt.Printf("failed to register scheme: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// +kubebuilder:scaffold:scheme | ||
|
||
k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme}) | ||
if err != nil { | ||
fmt.Printf("failed to setup a Kubernetes client: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
code := m.Run() | ||
|
||
err = testEnv.Stop() | ||
if err != nil { | ||
fmt.Printf("failed to stop testEnv: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters