Example #1
0
func generateCommand(request reflect.Value) cli.Command {
	typ := request.Elem().Type()

	commandName := lowercase(strings.TrimSuffix(typ.Name(), "Request"))

	usage := USAGE[commandName]

	flags := []cli.Flag{}

	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)

		flag, ok := flagForField(field, usage.Flags)
		if ok {
			flags = append(flags, flag)
		}
	}

	return cli.Command{
		Name:        commandName,
		Flags:       flags,
		Usage:       usage.Usage,
		Description: usage.Description,
		Action: func(c *cli.Context) {
			cp := connectionInfo(c)

			conn, err := cp.ProvideConnection()
			if err != nil {
				fmt.Println("failed to connect to warden:", err)
				os.Exit(1)
			}

			request := requestFromInput(request, flags, c)

			response := warden.ResponseMessageForType(warden.TypeForMessage(request))

			encoder := json.NewEncoder(os.Stdout)

			if commandName == "attach" {
				err := conn.SendMessage(request)
				if err != nil {
					fmt.Println("request-response failed:", err)
					os.Exit(1)
				}

				streamProcessPayloads(conn, encoder)

				return
			}

			err = conn.RoundTrip(request, response)
			if err != nil {
				fmt.Println("request-response failed:", err)
				os.Exit(1)
			}

			if commandName == "streamOut" {
				streamStreamOut(conn)
				return
			}

			if commandName == "streamIn" {
				streamStreamIn(conn)
				return
			}

			encoder.Encode(response)

			if commandName == "run" {
				streamProcessPayloads(conn, encoder)
			}
		},
	}
}
Example #2
0
					fakeContainer := container.(*fake_backend.FakeContainer)

					fakeContainer.StreamedProcessChunks = []warden.ProcessStream{
						{
							ExitStatus: &exitStatus,
						},
					}
				})

				It("does not wait for it to complete", func() {
					writeMessages(request)

					time.Sleep(10 * time.Millisecond)

					before := time.Now()

					wardenServer.Stop()

					Expect(time.Since(before)).To(BeNumerically("<", 50*time.Millisecond))

					response := protocol.ResponseMessageForType(protocol.TypeForMessage(request))
					readResponse(response)

					_, err := protocol.Messages(&protocol.PingRequest{}).WriteTo(serverConnection)
					Expect(err).To(HaveOccurred())
				})
			})
		}
	})
})