MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestBuildWithBuildkitConfig

Function TestBuildWithBuildkitConfig

cmd/nerdctl/builder/builder_build_test.go:1028–1110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1026}
1027
1028func TestBuildWithBuildkitConfig(t *testing.T) {
1029 nerdtest.Setup()
1030
1031 testCase := &test.Case{
1032 Require: require.All(
1033 nerdtest.Build,
1034 require.Not(nerdtest.Docker),
1035 ),
1036 Setup: func(data test.Data, helpers test.Helpers) {
1037 dockerfile := fmt.Sprintf(`FROM %s
1038CMD ["echo", "nerdctl-build-test-string"]`, testutil.CommonImage)
1039 data.Temp().Save(dockerfile, "Dockerfile")
1040 data.Labels().Set("buildCtx", data.Temp().Path())
1041
1042 },
1043 SubTests: []*test.Case{
1044 {
1045 Description: "build with buildkit-host",
1046 Setup: func(data test.Data, helpers test.Helpers) {
1047 // Get BuildkitAddr
1048 buildkitAddr, err := buildkitutil.GetBuildkitHost(testutil.Namespace)
1049 assert.NilError(helpers.T(), err)
1050 buildkitAddr = strings.TrimPrefix(buildkitAddr, "unix://")
1051
1052 // Symlink the buildkit Socket for testing
1053 symlinkedBuildkitAddr := filepath.Join(data.Temp().Path(), "buildkit.sock")
1054
1055 // Do a negative test to check the setup
1056 helpers.Fail("build", "-t", data.Identifier(), "--buildkit-host", fmt.Sprintf("unix://%s", symlinkedBuildkitAddr), data.Labels().Get("buildCtx"))
1057
1058 // Test build with the symlinked socket
1059 cmd := helpers.Custom("ln", "-s", buildkitAddr, symlinkedBuildkitAddr)
1060 cmd.Run(&test.Expected{
1061 ExitCode: 0,
1062 })
1063 helpers.Ensure("build", "-t", data.Identifier(), "--buildkit-host", fmt.Sprintf("unix://%s", symlinkedBuildkitAddr), data.Labels().Get("buildCtx"))
1064 },
1065 Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
1066 return helpers.Command("run", "--rm", data.Identifier())
1067 },
1068 Cleanup: func(data test.Data, helpers test.Helpers) {
1069 helpers.Anyhow("rmi", "-f", data.Identifier())
1070 },
1071 Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")),
1072 },
1073 {
1074 Description: "build with env specified",
1075 Setup: func(data test.Data, helpers test.Helpers) {
1076 // Get BuildkitAddr
1077 buildkitAddr, err := buildkitutil.GetBuildkitHost(testutil.Namespace)
1078 assert.NilError(helpers.T(), err)
1079 buildkitAddr = strings.TrimPrefix(buildkitAddr, "unix://")
1080
1081 // Symlink the buildkit Socket for testing
1082 symlinkedBuildkitAddr := filepath.Join(data.Temp().Path(), "buildkit-env.sock")
1083
1084 // Do a negative test to ensure setting up the env variable is effective
1085 cmd := helpers.Command("build", "-t", data.Identifier(), data.Labels().Get("buildCtx"))

Callers

nothing calls this directly

Calls 15

RunMethod · 0.95
SetupFunction · 0.92
GetBuildkitHostFunction · 0.92
SaveMethod · 0.65
TempMethod · 0.65
SetMethod · 0.65
LabelsMethod · 0.65
PathMethod · 0.65
TMethod · 0.65
FailMethod · 0.65
IdentifierMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…