Skip to content

Commit

Permalink
Merge pull request jaegertracing#42 from IshwarKanse/rebase-bot-main
Browse files Browse the repository at this point in the history
  • Loading branch information
openshift-merge-bot[bot] authored Sep 22, 2024
2 parents f316aff + cb1d78c commit c459dc0
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ jobs:
- run: rm -rf ./tests

- name: Initialize CodeQL
uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
uses: github/codeql-action/init@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
with:
languages: go

- name: Autobuild
uses: github/codeql-action/autobuild@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
uses: github/codeql-action/autobuild@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
uses: github/codeql-action/analyze@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
2 changes: 1 addition & 1 deletion .github/workflows/ossf-scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
uses: github/codeql-action/upload-sarif@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
with:
sarif_file: results.sarif
77 changes: 77 additions & 0 deletions controllers/elasticsearch/elasticsearch_controller_test.go
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)
}
57 changes: 57 additions & 0 deletions controllers/elasticsearch/suit_test.go
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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
go.opentelemetry.io/otel/trace v1.30.0
go.uber.org/zap v1.27.0
gomodules.xyz/jsonpatch/v2 v2.4.0
google.golang.org/grpc v1.66.1
google.golang.org/grpc v1.66.2
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM=
google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo=
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit c459dc0

Please sign in to comment.