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

[chore] move tests to non deprecated packages, fix chloggen #6673

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .chloggen/moveext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ change_type: deprecation
component: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate Extension related -s from component package in favor of extension package.
note: Deprecate Extension related types/funcs from component package in favor of extension package.

# One or more tracking issues or pull requests related to the change
issues: [6578]
Expand Down
37 changes: 0 additions & 37 deletions component/factories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMakeExtensionFactoryMap(t *testing.T) {
type testCase struct {
name string
in []ExtensionFactory
out map[Type]ExtensionFactory
}

p1 := NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha)
p2 := NewExtensionFactory("p2", nil, nil, StabilityLevelAlpha)
testCases := []testCase{
{
name: "different names",
in: []ExtensionFactory{p1, p2},
out: map[Type]ExtensionFactory{
p1.Type(): p1,
p2.Type(): p2,
},
},
{
name: "same name",
in: []ExtensionFactory{p1, p2, NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha)},
},
}
for i := range testCases {
tt := testCases[i]
t.Run(tt.name, func(t *testing.T) {
out, err := MakeExtensionFactoryMap(tt.in...)
if tt.out == nil {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.out, out)
})
}
}

func TestMakeReceiverFactoryMap(t *testing.T) {
type testCase struct {
name string
Expand Down
39 changes: 38 additions & 1 deletion extension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type nopExtension struct {
component.ShutdownFunc
}

func TestNewExtensionFactory(t *testing.T) {
func TestNewFactory(t *testing.T) {
const typeStr = "test"
defaultCfg := config.NewExtensionSettings(component.NewID(typeStr))
nopExtensionInstance := new(nopExtension)
Expand All @@ -49,3 +49,40 @@ func TestNewExtensionFactory(t *testing.T) {
assert.NoError(t, err)
assert.Same(t, nopExtensionInstance, ext)
}

func TestMakeFactoryMap(t *testing.T) {
type testCase struct {
name string
in []Factory
out map[component.Type]Factory
}

p1 := NewFactory("p1", nil, nil, component.StabilityLevelAlpha)
p2 := NewFactory("p2", nil, nil, component.StabilityLevelAlpha)
testCases := []testCase{
{
name: "different names",
in: []Factory{p1, p2},
out: map[component.Type]Factory{
p1.Type(): p1,
p2.Type(): p2,
},
},
{
name: "same name",
in: []Factory{p1, p2, NewFactory("p1", nil, nil, component.StabilityLevelAlpha)},
},
}
for i := range testCases {
tt := testCases[i]
t.Run(tt.name, func(t *testing.T) {
out, err := MakeFactoryMap(tt.in...)
if tt.out == nil {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.out, out)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package componenttest
package extensiontest

import (
"context"
Expand All @@ -22,18 +22,18 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/component/componenttest"
)

func TestNewNopExtensionFactory(t *testing.T) {
factory := NewNopExtensionFactory()
func TestNewNopFactory(t *testing.T) {
factory := NewNopFactory()
require.NotNil(t, factory)
assert.Equal(t, component.Type("nop"), factory.Type())
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(component.NewID("nop"))}, cfg)
// assert.Equal(t, &nopConfig{ExtensionSettings: config.NewExtensionSettings(component.NewID("nop"))}, cfg)

traces, err := factory.CreateExtension(context.Background(), NewNopExtensionCreateSettings(), cfg)
traces, err := factory.CreateExtension(context.Background(), NewNopCreateSettings(), cfg)
require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, traces.Shutdown(context.Background()))
}