module yumaworks-test {

  namespace "http://yumaworks.com/ns/yumaworks-test";

  prefix "ywtest";

  import yuma-types { prefix yt; }
  import yumaworks-extensions { prefix ywx; }

  organization "YumaWorks, Inc.";

  contact
    "Support <support@yumaworks.com>";

  description
    "This module contains data structures representing
     replayable test suites for specific use cases and YANG modules

        +---------------------+
      +-+------------------+  |
      |                    |  |
      |     Test Suite     |  |
      |                    |--+
      +--------------------+
       |          |
       |          |
       |          V
       |    +---------------------+
       |  +-+------------------+  |
       |  |                    |  |
       |  |        Test        |  |
       |  |                    |--+
       |  +--------------------+
       |          |
       |          |
       |          V
       |      +---------------------+
       |    +-+------------------+  |
       |    |                    |  |
       |    |        Step        |  |
       |    |                    |--+
       |    +--------------------+
       |
       V
      +---------------------+
    +-+------------------+  |
    |                    |  |
    |      Servers       |  |
    |                    |--+
    +--------------------+
              |
              |
              V
        +---------------------+
      +-+------------------+  |
      |                    |  |
      |      Sessions      |  |
      |                    |--+
      +--------------------+


     Copyright (c) 2013 - 2023 YumaWorks, Inc. All rights reserved.

     Redistribution and use in source and binary forms, with or
     without modification, is permitted pursuant to, and subject
     to the license terms contained in, the BSD 3-Clause License
     http://opensource.org/licenses/BSD-3-Clause";

  revision 2023-03-16 {
    description
       "Add message-indent parameter";
  }

  revision 2013-03-31 {
    description
       "Rename to yumaworks-test";
  }

  revision 2013-01-21 {
    description
       "Initial version";
  }

  typedef response-type {
    type enumeration {
      enum none {
        description "Local command, no <rpc-reply> expected.";
      }
      enum ok {
        description "Expecting the <ok> reply.";
      }
      enum data {
        description "Expecting a data reply.";
      }
      enum error {
        description "Expecting an rpc-error reply.";
      }
    }
    description
      "The type of response expected from the server
       for this request.";
  }

  container test-suites {

     list test-suite {

      key name;

      leaf name {
        type yt:NcxName;
         description
          "The test suite name.";
      }

      leaf description {
        type string;
        description "Description of this test suite.";
      }

      container setup {
        ywx:cli-text-block;
        description "Test suite setup commands";
      }

      container cleanup {
        ywx:cli-text-block;
        description "Test suite cleanup commands";
      }

      leaf-list run-test {
        ordered-by user;
        type yt:NcxName;
        min-elements 1;
        description
          "The ordered list of test names to run in this test suite.
           At least 1 test must be specified.";
      }

      leaf message-indent {
        type int8 {
          range "-1 .. 9";
        }
        default 2;
        description "message-indent used for the test.";
      }

      list test {
        description
          "The unit-tests that are configured to be run.
           At least 1 test must be configured.";
        ordered-by user;
        min-elements 1;
        key name;

        leaf name {
          type yt:NcxName;
          description "The name of this unit test.";
        }

        leaf description {
          type string;
          description "Description of this unit test.";
        }

        leaf-list must-pass {
          type yt:NcxName;
          description
           "The names of the tests that have already been
            run and pased for this test to be attempted,
            The test will be skipped if any test in the
            must-pass list has been attempted and the
            test failed.

            If the named test has not been run yet
            this test will fail and be skipped.  If the named
            test was skipped, then it will not cause this test
            to be skipped, only if it did not run at all or
            if it ran and passed.";
        }

        list step {
          description
            "A list of test steps to be done in order.";
          ordered-by user;
          key name;

          leaf name {
            type string {
              length "1 .. 64";
            }
            description "The name of this unit test step.";
          }

          leaf description {
            type string;
            description "Description of this unit test step.";
          }

          leaf session-name {
            type yt:NcxName;
            description
             "The name of the session to use.
              Empty if the test session should be used";
          }

          leaf result-type {
            type response-type;
            description
              "The expected response type. If this leaf is
               missing then any response type is acceptable.";
          }

          leaf result-error-tag {
            when "../result-type = 'error'";
            type string;
            description
              "The error-tag value expected if the result-type
               is 'error'.  If not set, then any error-tag
               value is acceptable.";
          }

          leaf result-error-apptag {
            when "../result-type = 'error'";
            type string;
            description
              "The error-app-tag value expected if the result-type
               is 'error'.  If not set, then any error-app-tag
               value is acceptable.";
          }

          leaf-list result-error-info {
            when "../result-type = 'error'";
            type yt:NcxName;
            description
              "The error-info element name expected if the result-type
               is 'error'.";
          }

          leaf command {
            type string;
            mandatory true;
            description "The yangcli command line string to use";
          }

          anyxml rpc-reply-data {
            when "../result-type = 'data'";
            description
              "The contents of <rpc-reply> element that are
                expected to be returned in the reply.
                This element itself represents <rpc-reply>
                and any child nodes are the nodes returned
                by the server.";
           }

         }  // list step
      }     // list test
    } // list test-suite
  } // container test-suites


}
