Ejemplo n.º 1
0
Archivo: main.go Proyecto: deoxxa/mllp
func main() {
	rx := regexp.MustCompile(os.Args[1])

	r := mllp.NewReader(os.Stdin)
	w := mllp.NewWriter(os.Stdout)

	i := 0
	for {
		m, err := r.ReadMessage()
		if err != nil {
			if stackerr.HasUnderlying(err, stackerr.Equals(io.EOF)) {
				break
			}

			panic(err)
		}

		if rx.Match(m) {
			if err := w.WriteMessage(m); err != nil {
				panic(err)
			}
		}

		i++
	}
}
Ejemplo n.º 2
0
func TestApplyWithExistingRemoveError(t *testing.T) {
	const image = "x"
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
		removeExisting: true,
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{
				Id:    "y",
				Image: "z",
			}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return []*dockerclient.Image{
				{
					RepoTags: []string{image},
					Id:       "y",
				},
			}, nil
		},
		removeContainer: func(id string, force, volumes bool) error {
			return givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 3
0
func TestApplyStartError(t *testing.T) {
	givenErr := errors.New("")
	const image = "x"
	const id = "y"
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{
				Id:     "a",
				Image:  id,
				Config: &dockerclient.ContainerConfig{},
			}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return []*dockerclient.Image{
				{
					RepoTags: []string{image},
					Id:       id,
				},
			}, nil
		},
		startContainer: func(id string, config *dockerclient.HostConfig) error {
			return givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 4
0
func TestApplyInitialInspectError(t *testing.T) {
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: "x",
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 5
0
func TestApplyGraphApplyError(t *testing.T) {
	givenErr := errors.New("")
	containers := []*Container{
		{
			name:            "n1",
			containerConfig: &dockerclient.ContainerConfig{Image: "in1"},
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, givenErr
		},
	}
	err := ApplyGraph(client, containers)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 6
0
func TestCheckExistingImageIdentifyError(t *testing.T) {
	givenErr := errors.New("")
	const image = "x"
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
	}
	client := &mockClient{
		listImages: func() ([]*dockerclient.Image, error) {
			return nil, givenErr
		},
	}
	ok, err := container.checkExisting(client, &dockerclient.ContainerInfo{Image: "z"})
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
	ensure.False(t, ok)
}
Ejemplo n.º 7
0
func TestApplyInspectAfterCreateError(t *testing.T) {
	container, err := NewContainer(
		ContainerName("x"),
		ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
	)
	ensure.Nil(t, err)
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, dockerclient.ErrNotFound
		},
		createContainer: func(config *dockerclient.ContainerConfig, name string) (string, error) {
			return "baz", nil
		},
	}
	err = container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(dockerclient.ErrNotFound)))
}
Ejemplo n.º 8
0
Archivo: main.go Proyecto: deoxxa/mllp
func main() {
	r := mllp.NewReader(os.Stdin)

	i := 0
	for {
		if _, err := r.ReadMessage(); err != nil {
			if stackerr.HasUnderlying(err, stackerr.Equals(io.EOF)) {
				break
			}

			panic(err)
		}

		i++
	}

	fmt.Printf("total messages: %d\n", i)
}
Ejemplo n.º 9
0
func TestApplyRemovesExistingWithoutDesiredImageError(t *testing.T) {
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: "x",
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{Id: "y", Image: "a"}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return nil, givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 10
0
func TestApplyForceRemoveExistingError(t *testing.T) {
	container, err := NewContainer(
		ContainerName("x"),
		ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
		ContainerForceRemoveExisting(),
	)
	ensure.Nil(t, err)
	givenErr := errors.New("")
	client := &mockClient{
		removeContainer: func(id string, force, volumes bool) error {
			return givenErr
		},
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{Id: "x"}, nil
		},
	}
	err = container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
Ejemplo n.º 11
0
func TestApplyAfterCreateError(t *testing.T) {
	givenErr := errors.New("")
	const givenName = "x"
	const givenID = "y"
	var inspectCalls, removeCalls int
	container, err := NewContainer(
		ContainerName(givenName),
		ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
		ContainerAfterCreate(func(string) error { return givenErr }),
	)
	ensure.Nil(t, err)
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			inspectCalls++
			switch inspectCalls {
			case 1:
				return nil, dockerclient.ErrNotFound
			case 2:
				return &dockerclient.ContainerInfo{Id: givenID}, nil
			}
			panic("not reached")
		},
		createContainer: func(config *dockerclient.ContainerConfig, name string) (string, error) {
			return "", nil
		},
		startContainer: func(id string, config *dockerclient.HostConfig) error {
			return nil
		},
		removeContainer: func(id string, force, volumes bool) error {
			removeCalls++
			ensure.DeepEqual(t, id, givenID)
			return nil
		},
	}
	err = container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
	ensure.DeepEqual(t, removeCalls, 1)
}