Repository: moby/moby
File: integration/daemon/nri/nri_test.go (Go)

Code before:
	}

	for _, tc := range testcases {
		t.Run(tc.name, func(t *testing.T) {
			stopPlugin := startBuiltinPlugin(ctx, t, builtinPluginConfig{
				pluginName:   "nri-test-plugin",
				pluginIdx:    "00",
				sockPath:     sockPath,
				ctrCreateAdj: tc.ctrCreateAdj,
			})
			defer stopPlugin()

			ctrId := container.Run(ctx, t, c)
			defer func() { _, _ = c.ContainerRemove(ctx, ctrId, client.ContainerRemoveOptions{Force: true}) }()

			inspect, err := c.ContainerInspect(ctx, ctrId, client.ContainerInspectOptions{})
			if assert.Check(t, err) {
				assert.Check(t, is.Contains(inspect.Container.Config.Env, tc.expEnv))
			}
		})
	}
}

func TestNRIContainerCreateAddMount(t *testing.T) {
	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
	skip.If(t, testEnv.DaemonInfo.OSType == "windows")
	skip.If(t, testEnv.IsRootless)

	ctx := testutil.StartSpan(baseContext, t)

	tmp := t.TempDir()
	sockPath := filepath.Join(tmp, "nri.sock")

	d := daemon.New(t)
	d.StartWithBusybox(ctx, t,
		"--nri-opts=enable=true,socket-path="+sockPath,
		"--iptables=false", "--ip6tables=false",
	)
	defer d.Stop(t)
	c := d.NewClientT(t)

	// Create and populate a directory for containers to mount.
	dirToMount := t.TempDir()
	if err := os.WriteFile(filepath.Join(dirToMount, "testfile.txt"), []byte("hello\n"), 0o644); err != nil {
		assert.NilError(t, err)
	}
	const (
		mountPoint  = "/mountpoint"
		ctrTestFile = "/mountpoint/testfile.txt"
		exitOk      = 0
		exitFail    = 1

Review comment (suggestion):
https://github.com/moby/moby/pull/51674#discussion_r2606963386

> I'm guessing "non windows" is also because we can't start a custom daemon with these options, right? Perhaps we should add a comment to the `skip` (Looking at "patch env-vars", I could imagine that can be supported on Windows as well, just not easy to test it).



Code after:

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			stopPlugin := startBuiltinPlugin(ctx, t, builtinPluginConfig{
				pluginName:   "nri-test-plugin",
				pluginIdx:    "00",
				sockPath:     sockPath,
				ctrCreateAdj: tc.ctrCreateAdj,
			})
			defer stopPlugin()

			ctrId := container.Run(ctx, t, c)
			defer func() { _, _ = c.ContainerRemove(ctx, ctrId, client.ContainerRemoveOptions{Force: true}) }()

			inspect, err := c.ContainerInspect(ctx, ctrId, client.ContainerInspectOptions{})
			if assert.Check(t, err) {
				assert.Check(t, is.Contains(inspect.Container.Config.Env, tc.expEnv))
			}
		})
	}
}

func TestNRIContainerCreateAddMount(t *testing.T) {
	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "cannot start a separate daemon with NRI enabled on Windows")
	skip.If(t, testEnv.IsRootless)

	ctx := testutil.StartSpan(baseContext, t)

	sockPath := filepath.Join(t.TempDir(), "nri.sock")

	d := daemon.New(t)
	d.StartWithBusybox(ctx, t,
		"--nri-opts=enable=true,socket-path="+sockPath,
		"--iptables=false", "--ip6tables=false",
	)
	defer d.Stop(t)
	c := d.NewClientT(t)

	// Create and populate a directory for containers to mount.
	dirToMount := t.TempDir()
	if err := os.WriteFile(filepath.Join(dirToMount, "testfile.txt"), []byte("hello\n"), 0o644); err != nil {
		assert.NilError(t, err)
	}
	const (
		mountPoint  = "/mountpoint"
		ctrTestFile = "/mountpoint/testfile.txt"
		exitOk      = 0
		exitFail    = 1
	)