<commit_before>import {expect} from "chai";

import AppFormModelPostProcess
  from "../../js/stores/transforms/AppFormModelPostProcess";

import ContainerConstants from "../../js/constants/ContainerConstants";

describe("App Form Model Post Process", function () {

  it("empty accepted resource roles defaults to '*'", function () {
    var app = {
      acceptedResourceRoles: []
    };

    AppFormModelPostProcess.acceptedResourceRoles(app);

    expect(app).to.deep.equal({acceptedResourceRoles: ["*"]});
  });

  describe("container", function () {

    it("empty container values to null", function () {
      var app = {
        container: {
          type: "DOCKER",
          volumes: [],
          docker: {
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app.container).to.equal(null);
    });

    it("doesn't touch non-empty containers", function () {
      var app = {
        container: {
          volumes: [],
          docker: {
            image: "group/image",
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app).to.deep.equal(app);
    });

    it("overrides blank cmd with null when a container is set", function () {
      var app = {
        cmd: "",
        container: {
          volumes: [],
          docker: {
            image: "group/image",
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app.cmd).to.equal(null);
    });

  });

  describe("health checks", function () {

    it("is empty on spefific object", function () {
      var app = {
        healthChecks: [{
          "path": null,
          "protocol": "HTTP",
          "portIndex": 0,
          "gracePeriodSeconds": 300,
          "intervalSeconds": 60,
          "timeoutSeconds": 20,
          "maxConsecutiveFailures": 3,
          "ignoreHttp1xx": false
        }]
      };<commit_msg>Add tests for HOST network default policy<commit_after>import {expect} from "chai";

import AppFormModelPostProcess
  from "../../js/stores/transforms/AppFormModelPostProcess";

import ContainerConstants from "../../js/constants/ContainerConstants";

describe("App Form Model Post Process", function () {

  it("empty accepted resource roles defaults to '*'", function () {
    var app = {
      acceptedResourceRoles: []
    };

    AppFormModelPostProcess.acceptedResourceRoles(app);

    expect(app).to.deep.equal({acceptedResourceRoles: ["*"]});
  });

  describe("container", function () {

    it("empty container values to null", function () {
      var app = {
        container: {
          type: "DOCKER",
          volumes: [],
          docker: {
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app.container).to.equal(null);
    });

    it("doesn't touch non-empty containers", function () {
      var app = {
        container: {
          volumes: [],
          docker: {
            image: "group/image",
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app).to.deep.equal(app);
    });

    it("overrides blank cmd with null when a container is set", function () {
      var app = {
        cmd: "",
        container: {
          volumes: [],
          docker: {
            image: "group/image",
            portMappings: [],
            parameters: []
          }
        }
      };

      AppFormModelPostProcess.container(app);

      expect(app.cmd).to.equal(null);
    });

    it("sets network mode to HOST when not specified", function () {
      var app = {
        container: {
          docker: {
            image: "group/image"
          },
          type: "DOCKER"
        }
      };
      var app2 = Object.assign({}, app);
      AppFormModelPostProcess.container(app2);

      expect(app2.container.docker.network)
        .to.equal(ContainerConstants.NETWORK.HOST);
    });

    it("sets network mode to HOST when nothing is selected", function () {
      var app = {
        container: {
          docker: {
            image: "group/image",
            network: ContainerConstants.NETWORK.BRIDGE
          },
          type: "DOCKER"
        }
      };
      var app2 = Object.assign({}, app);
      AppFormModelPostProcess.container(app2);

      expect(app2.container.docker.network)
        .to.equal(ContainerConstants.NETWORK.BRIDGE);
    });

  });

  describe("health checks", function () {

    it("is empty on spefific object", function () {
      var app = {
        healthChecks: [{
          "path": null,
          "protocol": "HTTP",
          "portIndex": 0,
          "gracePeriodSeconds": 300,
          "intervalSeconds": 60,
          "timeoutSeconds": 20,
          "maxConsecutiveFailures": 3,
          "ignoreHttp1xx": false
        }]
      };
{'fraction_non_alphanumeric': 0.13618524332810047, 'fraction_numerical': 0.00510204081632653, 'mean_word_length': 1.8634831460674157, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5281277', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1397, 'n_words': 289}