Пример #1
0
func main() {
	flag.StringVar(&configFilePath, "config", configFilePath, "configuration file")
	flag.Parse()

	settings, err := config.ReadConfigFile(configFilePath)
	if err != nil {
		log.Fatal("FATAL while reading config files: ", err)
	}
	if len(settings.Docker) == 0 {
		log.Fatal("FATAL: empty docker configuration list:\n", settings)
	}

	client, err := dckr.NewClientFirstOf(settings.Docker)
	if err != nil {
		log.Print(err)
		log.Fatal("Failed to make any docker client, exiting")
	}

	server := server.NewServer(settings.Server, client)
	log.Println("Starting GEF server at: ", settings.Server.Address)
	err = server.Start()
	if err != nil {
		log.Println("GEF server failed: ", err)
	}
}
Пример #2
0
func TestClient(t *testing.T) {
	settings, err := config.ReadConfigFile(configFilePath)
	if err != nil {
		t.Error("FATAL while reading config files: ", err)
	}
	clientConf = settings.Docker
	c := newClient(t)

	before := listImages(c, t)

	img := buildImage(c, t)

	after := listImages(c, t)

	errstr := "Cannot find new image in list"
	for _, x := range after {
		if x.ID == img.ID {
			errstr = ""
			break
		}
	}

	if errstr != "" {
		t.Error("before is: ", len(before), before)
		t.Error("image is: ", img)
		t.Error("after is: ", len(after), after)
		t.Error("")
		t.Error(errstr)
		t.Fail()
		return
	}

	containerID := executeImage(c, img.ID, t)
	log.Println("executed container: ", containerID)

	containerList := listContainers(c, t)
	if len(containerList) == 0 {
		t.Error("cannot find any containers")
		t.Fail()
		return
	}

	found := false
	for _, container := range containerList {
		if container.ID == containerID {
			found = true
		}
	}
	if !found {
		t.Error("cannot find the executed container in the list of all containers")
		t.Fail()
		return
	}

	inspectContainer(c, containerID, t)
}
Пример #3
0
func TestServer(t *testing.T) {
	settings, err := config.ReadConfigFile(configFilePath)
	if err != nil {
		t.Error("FATAL while reading config files: ", err)
	}
	clientConf = settings.Docker

	c := newClient(t)
	s := server.NewServer(settings.Server, c)

	srv := httptest.NewServer(s.Server.Handler)
	baseURL := srv.URL + "/api/"

	checkIfAPIExist(baseURL, t)
	callListVolumesHandler(baseURL+"volumes", t)
	callListJobsHandler(baseURL+"jobs", t)
	callListServicesHandler(baseURL+"images", t)
}