(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestRunAddHost(t *testing.T) { |
| 200 | // Not parallelizable (https://github.com/containerd/nerdctl/issues/1127) |
| 201 | base := testutil.NewBase(t) |
| 202 | base.Cmd("run", "--rm", "--add-host", "testing.example.com:10.0.0.1", testutil.AlpineImage, "cat", "/etc/hosts").AssertOutWithFunc(func(stdout string) error { |
| 203 | var found bool |
| 204 | sc := bufio.NewScanner(bytes.NewBufferString(stdout)) |
| 205 | for sc.Scan() { |
| 206 | // removing spaces and tabs separating items |
| 207 | line := strings.ReplaceAll(sc.Text(), " ", "") |
| 208 | line = strings.ReplaceAll(line, "\t", "") |
| 209 | if strings.Contains(line, "10.0.0.1testing.example.com") { |
| 210 | found = true |
| 211 | } |
| 212 | } |
| 213 | if !found { |
| 214 | return errors.New("host was not added") |
| 215 | } |
| 216 | return nil |
| 217 | }) |
| 218 | base.Cmd("run", "--rm", "--add-host", "test:10.0.0.1", "--add-host", "test1:10.0.0.1", testutil.AlpineImage, "cat", "/etc/hosts").AssertOutWithFunc(func(stdout string) error { |
| 219 | var found int |
| 220 | sc := bufio.NewScanner(bytes.NewBufferString(stdout)) |
| 221 | for sc.Scan() { |
| 222 | // removing spaces and tabs separating items |
| 223 | line := strings.ReplaceAll(sc.Text(), " ", "") |
| 224 | line = strings.ReplaceAll(line, "\t", "") |
| 225 | if strutil.InStringSlice([]string{"10.0.0.1test", "10.0.0.1test1"}, line) { |
| 226 | found++ |
| 227 | } |
| 228 | } |
| 229 | if found != 2 { |
| 230 | return fmt.Errorf("host was not added, found %d", found) |
| 231 | } |
| 232 | return nil |
| 233 | }) |
| 234 | base.Cmd("run", "--rm", "--add-host", "10.0.0.1:testing.example.com", testutil.AlpineImage, "cat", "/etc/hosts").AssertFail() |
| 235 | |
| 236 | response := "This is the expected response for --add-host special IP test." |
| 237 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 238 | io.WriteString(w, response) |
| 239 | }) |
| 240 | const hostPort = 8081 |
| 241 | s := http.Server{Addr: fmt.Sprintf(":%d", hostPort), Handler: nil, ReadTimeout: 30 * time.Second} |
| 242 | go s.ListenAndServe() |
| 243 | defer s.Shutdown(context.Background()) |
| 244 | base.Cmd("run", "--rm", "--add-host", "test:host-gateway", testutil.NginxAlpineImage, "curl", fmt.Sprintf("test:%d", hostPort)).AssertOutExactly(response) |
| 245 | } |
| 246 | |
| 247 | func TestRunAddHostWithCustomHostGatewayIP(t *testing.T) { |
| 248 | // Not parallelizable (https://github.com/containerd/nerdctl/issues/1127) |
nothing calls this directly
no test coverage detected
searching dependent graphs…