Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "github.com/edwarnicke/exechelper" |
| 7 | ) |
| 8 | |
| 9 | func (s *NsSuite) TestHttpTps() { |
| 10 | t := s.T() |
| 11 | finished := make(chan error, 1) |
| 12 | server_ip := "10.0.0.2" |
| 13 | port := "8080" |
| 14 | dockerInstance := "http-tps" |
| 15 | |
| 16 | t.Log("starting vpp..") |
| 17 | |
| 18 | err := dockerRun(dockerInstance, "") |
| 19 | if err != nil { |
| 20 | t.Errorf("%v", err) |
| 21 | return |
| 22 | } |
| 23 | defer func() { exechelper.Run("docker stop " + dockerInstance) }() |
| 24 | |
| 25 | // start & configure vpp in the container |
| 26 | _, err = hstExec(dockerInstance, dockerInstance) |
| 27 | if err != nil { |
| 28 | t.Errorf("%v", err) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | go startWget(finished, server_ip, port, "client") |
| 33 | // wait for client |
| 34 | err = <-finished |
| 35 | if err != nil { |
| 36 | t.Errorf("%v", err) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func (s *Veths2Suite) TestHttpCli() { |
| 41 | t := s.T() |
| 42 | |
| 43 | srvInstance := "http-cli-srv" |
| 44 | clnInstance := "http-cli-cln" |
| 45 | err := dockerRun(srvInstance, "") |
| 46 | if err != nil { |
| 47 | t.Errorf("%v", err) |
| 48 | return |
| 49 | } |
| 50 | defer func() { exechelper.Run("docker stop " + srvInstance) }() |
| 51 | |
| 52 | err = dockerRun(clnInstance, "") |
| 53 | if err != nil { |
| 54 | t.Errorf("%v", err) |
| 55 | return |
| 56 | } |
| 57 | defer func() { exechelper.Run("docker stop " + clnInstance) }() |
| 58 | |
| 59 | _, err = hstExec("2veths srv", srvInstance) |
| 60 | if err != nil { |
| 61 | t.Errorf("%v", err) |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | _, err = hstExec("2veths cln", clnInstance) |
| 66 | if err != nil { |
| 67 | t.Errorf("%v", err) |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | t.Log("configured IPs...") |
| 72 | |
| 73 | _, err = hstExec("http-cli-srv", srvInstance) |
| 74 | if err != nil { |
| 75 | t.Errorf("%v", err) |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | t.Log("configured http server") |
| 80 | |
| 81 | o, err := hstExec("http-cli-cln /show/version", clnInstance) |
| 82 | if err != nil { |
| 83 | t.Errorf("%v", err) |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | if strings.Index(o, "<html>") < 0 { |
| 88 | t.Error("<html> not found in the result!") |
| 89 | } |
| 90 | } |