diff --git a/.dockerignore b/.dockerignore index d1a8d5f..f1fa7d6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,7 +3,6 @@ LICENSE *.log README.md requirements.txt -test_* Dockerfile *docker-test* *.log diff --git a/.drone.yml b/.drone.yml index 87d4e72..7ffd693 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,5 @@ kind: pipeline name: default - steps: - name: docker image: plugins/docker @@ -27,6 +26,40 @@ steps: repo: git.jbranan.com/jblu/crane tags: - dev + when: + branch: + - dev* +- name: test-main + image: git.jbranan.com/jblu/crane:latest + environment: + CRANE_HOST: + from_secret: CRANE_HOST + CRANE_PORT: + from_secret: CRANE_PORT + CRANE_ENDPOINT: + from_secret: CRANE_ENDPOINT + commands: + - echo $CRANE_HOST + - echo $CRANE_PORT + - echo $CRANE_ENDPOINT + - python test_crane.py + when: + branch: + - main +- name: test-dev + image: git.jbranan.com/jblu/crane:dev + environment: + CRANE_HOST: + from_secret: CRANE_HOST + CRANE_PORT: + from_secret: CRANE_PORT + CRANE_ENDPOINT: + from_secret: CRANE_ENDPOINT + commands: + - echo $CRANE_HOST + - echo $CRANE_PORT + - echo $CRANE_ENDPOINT + - python test_crane.py when: branch: - dev* \ No newline at end of file diff --git a/test_crane.py b/test_crane.py index 2e96a48..5ad2ee8 100644 --- a/test_crane.py +++ b/test_crane.py @@ -4,23 +4,32 @@ import json from tomllib import load from cclient import c_get_filtered_containers, c_start_container, c_stop_container, c_get_container_id from cprocess import process_cont_list -unittest.TestLoader.sortTestMethodsUsing = None -requests.packages.urllib3.disable_warnings() +# unittest.TestLoader.sortTestMethodsUsing = None +import os class TestCrane(unittest.TestCase): def setUp(self): - with open('./config.toml', 'rb') as c: - self.config = load(c) - self.host = self.config["portainer"]["host"] - self.port = self.config["portainer"]["port"] - self.access_token = "ptr_ufS1nADXmrU3QSN3bvITLMQ7oOH9yo3ECb/QNwtIYJ4=" - self.endpoint = self.config["portainer"]["endpoint"] self.req_obj = requests self.j_obj = json + self.req_obj.packages.urllib3.disable_warnings() + config_file_path = './docker/config.toml' + if os.getenv("toml_path", os.path.exists(config_file_path)): + with open(config_file_path, 'rb') as c: + self.config = load(c) + self.host = self.config["portainer"]["host"] + self.port = self.config["portainer"]["port"] + self.endpoint = self.config["portainer"]["endpoint"] + else: + self.host = os.getenv("CRANE_HOST", "192.168.4.11") + self.port = os.getenv("CRANE_PORT", 9443) + self.endpoint = os.getenv("CRANE_ENDPOINT", 1) + self.access_token = "ptr_ufS1nADXmrU3QSN3bvITLMQ7oOH9yo3ECb/QNwtIYJ4=" self.hypercare_containers = ['hottub'] self.status_filters = ["paused","dead","created","exited","removing","restarting","created"] def test_c_get_filtered_containers(self): + self.cid = c_get_container_id(self.req_obj,self.j_obj, self.host, self.port, self.access_token, self.endpoint, self.hypercare_containers,self.status_filters) + self.c_stop_container_response = c_stop_container(self.req_obj, self.host, self.port, self.access_token, self.endpoint, self.cid) self.cont_obj = c_get_filtered_containers(self.req_obj,self.j_obj, self.host, self.port, self.access_token, self.endpoint,self.hypercare_containers,self.status_filters) self.assertTrue(self.cont_obj, "No cont object returned by c_get_filtered_containers.")