-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
927 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright © 2024 Meroxa, Inc. | ||
// | ||
// 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 builtin | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/conduitio/conduit-connector-protocol/pconnector" | ||
"github.com/conduitio/conduit/pkg/foundation/cerrors" | ||
"github.com/conduitio/conduit/pkg/foundation/log" | ||
"github.com/conduitio/conduit/pkg/plugin" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/matryer/is" | ||
) | ||
|
||
func TestRegistry_InitList(t *testing.T) { | ||
is := is.New(t) | ||
ctx := context.Background() | ||
|
||
underTest := NewRegistry(log.Nop(), DefaultBuiltinConnectors, nil) | ||
underTest.Init(ctx) | ||
|
||
specs := underTest.List() | ||
|
||
is.Equal(len(DefaultBuiltinConnectors), len(specs)) | ||
for _, gotSpec := range specs { | ||
wantSpec := DefaultBuiltinConnectors["github.com/conduitio/conduit-connector-"+gotSpec.Name].NewSpecification() | ||
is.Equal( | ||
"", | ||
cmp.Diff( | ||
pconnector.Specification(wantSpec), | ||
gotSpec, | ||
cmpopts.IgnoreFields(pconnector.Specification{}, "SourceParams", "DestinationParams"), | ||
), | ||
) | ||
} | ||
} | ||
|
||
func TestRegistry_NewDispenser_PluginNotFound(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
pluginName string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "non-existing plugin", | ||
pluginName: "builtin:foobar", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "plugin exists, version doesn't", | ||
pluginName: "builtin:[email protected]", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "existing plugin, no builtin prefix, no version", | ||
pluginName: "file", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "existing plugin, with builtin prefix, no version", | ||
pluginName: "builtin:file", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "existing plugin, with builtin prefix, with version", | ||
pluginName: func() string { | ||
v := DefaultBuiltinConnectors["github.com/conduitio/conduit-connector-file"]. | ||
NewSpecification(). | ||
Version | ||
return "builtin:file@" + v | ||
}(), | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
is := is.New(t) | ||
ctx := context.Background() | ||
|
||
underTest := NewRegistry(log.Nop(), DefaultBuiltinConnectors, nil) | ||
underTest.Init(ctx) | ||
|
||
dispenser, err := underTest.NewDispenser(log.Nop(), plugin.FullName(tc.pluginName), pconnector.PluginConfig{}) | ||
if tc.wantErr { | ||
is.True(cerrors.Is(err, plugin.ErrPluginNotFound)) | ||
is.True(dispenser == nil) | ||
return | ||
} | ||
|
||
is.NoErr(err) | ||
is.True(dispenser != nil) | ||
}) | ||
} | ||
} |
Oops, something went wrong.