|
| 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 image |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "strings" |
| 22 | + "testing" |
| 23 | + |
| 24 | + testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" |
| 25 | + "github.com/containerd/nerdctl/v2/pkg/testutil" |
| 26 | + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" |
| 27 | + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry" |
| 28 | + "github.com/containerd/nerdctl/v2/pkg/testutil/test" |
| 29 | +) |
| 30 | + |
| 31 | +func TestImagePullPlainHttpWithDefaultPort(t *testing.T) { |
| 32 | + nerdtest.Setup() |
| 33 | + |
| 34 | + var reg *registry.Server |
| 35 | + |
| 36 | + testCase := &test.Case{ |
| 37 | + Require: test.Require( |
| 38 | + nerdtest.Registry, |
| 39 | + test.Not(nerdtest.Docker), |
| 40 | + nerdtest.Build, |
| 41 | + ), |
| 42 | + Setup: func(data test.Data, helpers test.Helpers) { |
| 43 | + reg = nerdtest.RegistryWithNoAuth(data, helpers, 80, false) |
| 44 | + reg.Setup(data, helpers) |
| 45 | + |
| 46 | + testImageRef := fmt.Sprintf("%s/%s:%s", |
| 47 | + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) |
| 48 | + dockerfile := fmt.Sprintf(`FROM %s |
| 49 | +CMD ["echo", "nerdctl-build-test-string"] |
| 50 | + `, testutil.CommonImage) |
| 51 | + |
| 52 | + buildCtx := testhelpers.CreateBuildContext(t, dockerfile) |
| 53 | + helpers.Ensure("build", "-t", testImageRef, buildCtx) |
| 54 | + helpers.Ensure("--insecure-registry", "push", testImageRef) |
| 55 | + helpers.Ensure("rmi", "-f", testImageRef) |
| 56 | + }, |
| 57 | + Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { |
| 58 | + testImageRef := fmt.Sprintf("%s/%s:%s", |
| 59 | + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) |
| 60 | + return helpers.Command("--insecure-registry", "pull", testImageRef) |
| 61 | + }, |
| 62 | + Expected: test.Expects(0, nil, nil), |
| 63 | + Cleanup: func(data test.Data, helpers test.Helpers) { |
| 64 | + if reg != nil { |
| 65 | + reg.Cleanup(data, helpers) |
| 66 | + testImageRef := fmt.Sprintf("%s/%s:%s", |
| 67 | + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) |
| 68 | + helpers.Anyhow("rmi", "-f", testImageRef) |
| 69 | + } |
| 70 | + }, |
| 71 | + } |
| 72 | + |
| 73 | + testCase.Run(t) |
| 74 | +} |
0 commit comments