func TestValidation(t *testing.T) {
	testCases := []struct {
		value    *api.Config
		expected []ValidationError
	}{
		{
			&api.Config{
				Source:            "http://github.com/openshift/source",
				BuilderImage:      "openshift/builder",
				DockerConfig:      &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
				BuilderPullPolicy: api.DefaultBuilderPullPolicy,
			},
			[]ValidationError{},
		},
		{
			&api.Config{
				Source:            "http://github.com/openshift/source",
				BuilderImage:      "openshift/builder",
				DockerConfig:      &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
				DockerNetworkMode: "foobar",
				BuilderPullPolicy: api.DefaultBuilderPullPolicy,
			},
			[]ValidationError{{ValidationErrorInvalidValue, "dockerNetworkMode"}},
		},
		{
			&api.Config{
				Source:            "http://github.com/openshift/source",
				BuilderImage:      "openshift/builder",
				DockerConfig:      &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
				DockerNetworkMode: api.NewDockerNetworkModeContainer("8d873e496bc3e80a1cb22e67f7de7be5b0633e27916b1144978d1419c0abfcdb"),
				BuilderPullPolicy: api.DefaultBuilderPullPolicy,
			},
			[]ValidationError{},
		},
		{
			&api.Config{
				Source:            "",
				BuilderImage:      "openshift/builder",
				DockerConfig:      &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
				DockerNetworkMode: api.NewDockerNetworkModeContainer("8d873e496bc3e80a1cb22e67f7de7be5b0633e27916b1144978d1419c0abfcdb"),
				BuilderPullPolicy: api.DefaultBuilderPullPolicy,
			},
			[]ValidationError{},
		},
	}
	for _, test := range testCases {
		result := ValidateConfig(test.value)
		if !reflect.DeepEqual(result, test.expected) {
			t.Errorf("got %+v, expected %+v", result, test.expected)
		}
	}
}
Exemple #2
0
// getDockerNetworkMode determines whether the builder is running as a container
// by examining /proc/self/cgroup. This contenxt is then passed to source-to-image.
func getDockerNetworkMode() s2iapi.DockerNetworkMode {
	file, err := os.Open("/proc/self/cgroup")
	if err != nil {
		return ""
	}
	defer file.Close()

	if id := readNetClsCGroup(file); id != "" {
		return s2iapi.NewDockerNetworkModeContainer(id)
	}
	return ""
}