#  -*- coding: utf-8 -*-
#   ECS ComposeX <https://github.com/lambda-my-aws/ecs_composex>
#   Copyright (C) 2020  John Mille <john@lambda-my-aws.io>
#  #
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#  #
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#  #
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

from ecs_composex.ecs.docker_tools import (
    set_memory_to_mb,
    find_closest_fargate_configuration,
)


def test_mb_settings():
    """
    Function to ensure the MB return works
    """
    assert set_memory_to_mb("1024") == 1024
    assert set_memory_to_mb("1G") == 1024
    assert set_memory_to_mb("0.5G") == 512
    assert set_memory_to_mb("4G") == 4096
    assert set_memory_to_mb(f"{1024*1024}kB") == 1024


def test_fargate_config():
    """
    Function to check the combination finding for Fargate
    """
    assert find_closest_fargate_configuration(256, 512, True) == "256!512"
    assert find_closest_fargate_configuration(2018, 4000, True) == "2048!4096"
    assert find_closest_fargate_configuration(2048, 25555) == (2048, 16384)
    assert find_closest_fargate_configuration(4096, 16385) == (4096, 17408)
    assert find_closest_fargate_configuration(4096, 17400) == (4096, 17408)
