mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Allow watchtower to update rebooting containers (#651)
Co-authored-by: nils måsén <nils@piksel.se> Co-authored-by: Simon Aronsson <simme@arcticbit.se>
This commit is contained in:
parent
64d48b70c2
commit
2842b97df3
6 changed files with 362 additions and 19 deletions
|
@ -1,13 +1,16 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NewMockAPIServer returns a mocked docker api server that responds to some fixed requests
|
||||
|
@ -18,16 +21,36 @@ func NewMockAPIServer() *httptest.Server {
|
|||
logrus.Debug("Mock server has received a HTTP call on ", r.URL)
|
||||
var response = ""
|
||||
|
||||
if isRequestFor("filters=%7B%22status%22%3A%7B%22running%22%3Atrue%7D%7D&limit=0", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/containers.json")
|
||||
} else if isRequestFor("filters=%7B%22status%22%3A%7B%22created%22%3Atrue%2C%22exited%22%3Atrue%2C%22running%22%3Atrue%7D%7D&limit=0", r) {
|
||||
if isRequestFor("filters=", r) {
|
||||
|
||||
Filters := r.URL.Query().Get("filters")
|
||||
var result map[string]interface{}
|
||||
json.Unmarshal([]byte(Filters), &result)
|
||||
status := result["status"].(map[string]interface{})
|
||||
|
||||
response = getMockJSONFromDisk("./mocks/data/containers.json")
|
||||
var x2 []types.Container
|
||||
var containers []types.Container
|
||||
json.Unmarshal([]byte(response), &containers)
|
||||
for _, v := range containers {
|
||||
for key := range status {
|
||||
if v.State == key {
|
||||
x2 = append(x2, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(x2)
|
||||
response = string(b)
|
||||
|
||||
} else if isRequestFor("containers/json?limit=0", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/containers.json")
|
||||
} else if isRequestFor("ae8964ba86c7cd7522cf84e09781343d88e0e3543281c747d88b27e246578b65", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/container_stopped.json")
|
||||
} else if isRequestFor("b978af0b858aa8855cce46b628817d4ed58e58f2c4f66c9b9c5449134ed4c008", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/container_running.json")
|
||||
} else if isRequestFor("ae8964ba86c7cd7522cf84e09781343d88e0e3543281c747d88b27e246578b67", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/container_restarting.json")
|
||||
} else if isRequestFor("sha256:19d07168491a3f9e2798a9bed96544e34d57ddc4757a4ac5bb199dea896c87fd", r) {
|
||||
response = getMockJSONFromDisk("./mocks/data/image01.json")
|
||||
} else if isRequestFor("sha256:4dbc5f9c07028a985e14d1393e849ea07f68804c4293050d5a641b138db72daa", r) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue