Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests in cmd/jaeger/internal #5069

Merged
merged 17 commits into from
Jan 19, 2024
Merged
2 changes: 0 additions & 2 deletions cmd/jaeger/internal/.nocover

This file was deleted.

24 changes: 15 additions & 9 deletions cmd/jaeger/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"log"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/otelcol"

Expand Down Expand Up @@ -41,15 +42,7 @@
otelRunE := cmd.RunE
cmd.RunE = func(cmd *cobra.Command, args []string) error {
configFlag := cmd.Flag("config")
if !configFlag.Changed {
log.Print("No '--config' flags detected, using default All-in-One configuration with memory storage.")
log.Print("To customize All-in-One behavior, pass a proper configuration.")
data, err := yamlAllInOne.ReadFile("all-in-one.yaml")
if err != nil {
return fmt.Errorf("cannot read embedded all-in-one configuration: %w", err)
}
configFlag.Value.Set("yaml:" + string(data))
}
handleConfigFlag(configFlag, args)

Check warning on line 45 in cmd/jaeger/internal/command.go

View check run for this annotation

Codecov / codecov/patch

cmd/jaeger/internal/command.go#L45

Added line #L45 was not covered by tests
return otelRunE(cmd, args)
}

Expand All @@ -58,3 +51,16 @@

return cmd
}

func handleConfigFlag(configFlag *pflag.Flag, args []string) error {
akagami-harsh marked this conversation as resolved.
Show resolved Hide resolved
if !configFlag.Changed {
log.Print("No '--config' flags detected, using default All-in-One configuration with memory storage.")
log.Print("To customize All-in-One behavior, pass a proper configuration.")
data, err := yamlAllInOne.ReadFile("all-in-one.yaml")
if err != nil {
return fmt.Errorf("cannot read embedded all-in-one configuration: %w", err)
}

Check warning on line 62 in cmd/jaeger/internal/command.go

View check run for this annotation

Codecov / codecov/patch

cmd/jaeger/internal/command.go#L61-L62

Added lines #L61 - L62 were not covered by tests
configFlag.Value.Set("yaml:" + string(data))
}
return nil
}
37 changes: 37 additions & 0 deletions cmd/jaeger/internal/command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"testing"

"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCommand(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd, "Command() should return a non-nil *cobra.Command instance")
assert.NotNil(t, cmd.RunE, "Command should have RunE function set")
}

func TestHandleConfigFlag(t *testing.T) {
configFlag := pflag.NewFlagSet("testFlagSet", pflag.ContinueOnError)
configFlag.String("config", "", "Path to the config file")

err := handleConfigFlag(configFlag.Lookup("config"), []string{})
require.NoError(t, err)
akagami-harsh marked this conversation as resolved.
Show resolved Hide resolved
}
37 changes: 37 additions & 0 deletions cmd/jaeger/internal/components_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestComponents(t *testing.T) {
factories, err := components()

require.NoError(t, err)

assert.NotNil(t, factories.Extensions)
assert.NotNil(t, factories.Receivers)
assert.NotNil(t, factories.Exporters)
assert.NotNil(t, factories.Processors)
assert.NotNil(t, factories.Connectors)

_, jaegerReceiverFactoryExists := factories.Receivers["jaeger"]
assert.True(t, jaegerReceiverFactoryExists)
}
25 changes: 25 additions & 0 deletions cmd/jaeger/internal/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"testing"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
}
Loading