# Path: collectors/lib/docker_engine/stats.py
# class Stats(object):
#     def __init__(self, container, mtime):
#         self.dims = [
#             "container_name=%s" % self.trim_container_name(container),
#             "container_id=%s" % container['Id'],
#             "image_name=%s" % container['Image'],
#             "image_id=%s" % container['ImageID']
#         ]
#         self.event_time = mtime
# 
#     @staticmethod
#     def trim_container_name(container):
#         return container["Names"][0].strip("/")


import unittest
import time
from collectors.lib.docker_engine.stats import Stats

class TestStats(unittest.TestCase):
    def setUp(self):
        self.now = time.gmtime()
        self.container = {
            "Names": ["/name"],
            "Id": "cntHASH",
            "Image": "qnib/test",
            "ImageID": "sha256:123"
        }

    def test_stats_dims(self):
        expected_dims = [
            "container_name=name",
            "container_id=cntHASH",
            "image_name=qnib/test",
            "image_id=sha256:123"
        ]

        s = Stats(self.container, self.now)

        self.assertEqual(expected_dims, s.dims)

    def test_stats_etime(self):
        s = Stats(self.container, self.now)
        self.assertEqual(self.now, s.event_time)

    def test_trim_container_name(self):
        # cnt = {"Names": ["/name"]}
        expected = "name"

# Path: collectors/lib/docker_engine/stats.py
# class Stats(object):
#     def __init__(self, container, mtime):
#         self.dims = [
#             "container_name=%s" % self.trim_container_name(container),
#             "container_id=%s" % container['Id'],
#             "image_name=%s" % container['Image'],
#             "image_id=%s" % container['ImageID']
#         ]
#         self.event_time = mtime
# 
#     @staticmethod
#     def trim_container_name(container):
#         return container["Names"][0].strip("/")


# Path: collectors/test/docker_engine/test_stats.py
import unittest
import time
from collectors.lib.docker_engine.stats import Stats


class TestStats(unittest.TestCase):
    def setUp(self):
        self.now = time.gmtime()
        self.container = {
            "Names": ["/name"],
            "Id": "cntHASH",
            "Image": "qnib/test",
            "ImageID": "sha256:123"
        }

    def test_stats_dims(self):
        expected_dims = [
            "container_name=name",
            "container_id=cntHASH",
            "image_name=qnib/test",
            "image_id=sha256:123"
        ]

        s = Stats(self.container, self.now)

        self.assertEqual(expected_dims, s.dims)

    def test_stats_etime(self):
        s = Stats(self.container, self.now)
        self.assertEqual(self.now, s.event_time)

    def test_trim_container_name(self):
        # cnt = {"Names": ["/name"]}
        expected = "name"

        self.assertEqual(expected, Stats.trim_container_name(self.container))