Skip to content

Commit ed419da

Browse files
committed
adaptation: add a version exchange test.
Add version exchange test and related test option to adaptation. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent 6808799 commit ed419da

3 files changed

Lines changed: 77 additions & 8 deletions

File tree

pkg/adaptation/adaptation_suite_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,6 +3310,39 @@ var _ = Describe("Plugin configuration request", func() {
33103310
})
33113311
})
33123312

3313+
var _ = Describe("NRI version exchange", func() {
3314+
var (
3315+
s = &Suite{}
3316+
)
3317+
3318+
AfterEach(func() {
3319+
s.Cleanup()
3320+
})
3321+
3322+
BeforeEach(func() {
3323+
s.Prepare(&mockRuntime{}, &mockPlugin{idx: "00", name: "test"})
3324+
})
3325+
3326+
It("should pass runtime version information to plugins", func() {
3327+
var (
3328+
runtimeName = "test-runtime"
3329+
runtimeVersion = "1.2.3"
3330+
nriVersion = "v9.8.7"
3331+
)
3332+
3333+
s.runtime.name = runtimeName
3334+
s.runtime.version = runtimeVersion
3335+
s.runtime.options = append(s.runtime.options, nri.WithTestNRIVersion(nriVersion))
3336+
3337+
s.Startup()
3338+
3339+
Expect(s.plugins[0].RuntimeName()).To(Equal(runtimeName))
3340+
Expect(s.plugins[0].RuntimeVersion()).To(Equal(runtimeVersion))
3341+
Expect(s.plugins[0].RuntimeNRIVersion()).To(Equal(nriVersion))
3342+
})
3343+
3344+
})
3345+
33133346
func protoDiff(a, b proto.Message) string {
33143347
return cmp.Diff(a, b, protocmp.Transform())
33153348
}

pkg/adaptation/helpers_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package adaptation
18+
19+
// WithTestNRIVersion is an option to override the local NRI version
20+
// for testing purposes.
21+
func WithTestNRIVersion(v string) Option {
22+
return func(r *Adaptation) error {
23+
r.nriVersion = v
24+
return nil
25+
}
26+
}

pkg/adaptation/suite_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ func (m *mockRuntime) update(ctx context.Context, updates []*nri.ContainerUpdate
366366
}
367367

368368
type mockPlugin struct {
369-
name string
370-
idx string
371-
stub stub.Stub
372-
mask stub.EventMask
369+
name string
370+
idx string
371+
stub stub.Stub
372+
mask stub.EventMask
373+
options []stub.Option
373374

374375
runtime string
375376
version string
@@ -457,10 +458,12 @@ func (m *mockPlugin) Init(dir string) error {
457458
m.Log("Init()...")
458459

459460
m.stub, err = stub.New(m,
460-
stub.WithPluginName(m.name),
461-
stub.WithPluginIdx(m.idx),
462-
stub.WithSocketPath(filepath.Join(dir, "nri.sock")),
463-
stub.WithOnClose(m.onClose),
461+
append(m.options,
462+
stub.WithPluginName(m.name),
463+
stub.WithPluginIdx(m.idx),
464+
stub.WithSocketPath(filepath.Join(dir, "nri.sock")),
465+
stub.WithOnClose(m.onClose),
466+
)...,
464467
)
465468
if err != nil {
466469
m.q.Add(PluginCreationError)
@@ -548,6 +551,13 @@ func (m *mockPlugin) RuntimeVersion() string {
548551
return m.version
549552
}
550553

554+
func (m *mockPlugin) RuntimeNRIVersion() string {
555+
if m.stub == nil {
556+
return ""
557+
}
558+
return m.stub.RuntimeNRIVersion()
559+
}
560+
551561
func (m *mockPlugin) onClose() {
552562
if m.stub != nil {
553563
m.stub.Stop()

0 commit comments

Comments
 (0)