Skip to content
Snippets Groups Projects
  1. Sep 05, 2012
    • Iustin Pop's avatar
      Further hlint fixes · 5b11f8db
      Iustin Pop authored
      Commit 2cdaf225, “Re-enable standard hlint warnings”, got it almost
      right. The only problem is that (confusingly) the default set of hints
      is not in HLint.Default, but in HLint.HLint (it includes Default and
      some built-ins).
      
      After changing the lint file to correctly include the defaults, we had
      another 128 suggestions:
      
        - Error: Eta reduce (2)
        - Error: Redundant bracket (4)
        - Error: Redundant do (17)
        - Error: Redundant lambda (7)
        - Error: Redundant return (1)
        - Warning: Avoid lambda (2)
        - Warning: Redundant $ (42)
        - Warning: Redundant bracket (35)
        - Warning: Use : (1)
        - Warning: Use String (4)
        - Warning: Use camelCase (10)
        - Warning: Use section (3)
      
      which are fixed by the current patch. Note that the 10 "Use camelCase"
      were all due to hlint not “knowing” the idiom of ‘case_’ (it does for
      ‘prop_’), for which I filled
      http://code.google.com/p/ndmitchell/issues/detail?id=558
      
      .
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      5b11f8db
    • Iustin Pop's avatar
      Rework CLI modules and tests · 51000365
      Iustin Pop authored
      
      While investigating how we could test the Daemon.hs module, I realised
      that we have a very, erm, sub-optimal situation:
      
      - HTools/CLI.hs has a nice IO/pure separation testing in cmdline
        parsing, which allows some basic functionality to be tested, but
        uses direct 'read' in many options, which fails at runtime when
        evaluating the argument, and not when parsing the options
      - Daemon.hs lacks that, but has a much nicer 'reqWithConversion'
        helper that can be used for nicer option parsing, and uses that +
        tryRead instead of plain 'read'
      
      Since this situation is very bad, let's clean it up. We introduce yet
      another module, Common.hs, that holds functionality common to all
      command line programs (daemons or not). We move the parsing to this
      module, and introduce a type class to handle option types which
      support --help/--version. This allows removal of duplicated code from
      CLI.hs and Daemon.hs.
      
      The other part of the patch is cleanup/rework of the tests for this
      code: we introduce some helpers (checkOpt, passFailOpt,
      checkEarlyExit) that can be used from the much-slimmer now tests for
      CLI and Daemon. In the common module, we just test the yes/no helper
      we have. Many new tests for boolean options and numeric options are
      added.
      
      A side change is the removal of the obsolete `--replay-count',
      `--test-size' options (unused since commit 95f6c931, “Switch Haskell
      test harness to test-framework”).
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      51000365
    • Iustin Pop's avatar
      Fix deserialisation bug in ResultEntry · 3ce788db
      Iustin Pop authored
      
      Found via the newly added unit-tests, which test most of the
      serialisation code in Query/Language (except for QueryResult, for
      which we already tests both sub-components separately).
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      3ce788db
    • Iustin Pop's avatar
      Add query filter tests · 90171729
      Iustin Pop authored
      
      These tests are node specific only because we don't have other query
      types implemented yet, but what they actually test is the various
      filter types.
      
      The tests are trying to cover most filter functionality; missing for
      now is proper checking for ContainsFilter and TrueFilter, the rest
      should be more or less covered.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      90171729
    • Iustin Pop's avatar
      Add some unittests for node queries · b9bdc10e
      Iustin Pop authored
      
      These new tests check that:
      
      - no known fields return unknown
      - any unknown field returns unknown
      - the type of the fields is consistent between the getters and the
        field definition
      - the length of each result row corresponds with the number of fields
        queried, and the length of the field definitions returned
      - the length of the rows corresponds to the number of nodes
      - querying fields on empty fields returns all fields
      
      Finally this patch found a bug, in that the pinst_list/sinst_list
      fields were declared as QFTNumber (copy-paste error from
      pinst_cnt/sinst_cnt), yay!
      
      I also changed genEmptyCluster to ensure that it generates unique node
      names, so that the number of result rows is consistent with what we
      requested, and switched ResultEntry from a normal constructor to
      record syntax, so that we can extract the fields without having to use
      pattern matching.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      b9bdc10e
    • Iustin Pop's avatar
      Add a small 'passTest' helper · 2e0bb81d
      Iustin Pop authored
      
      This is symmetric to failTest, and allows us to use it in cases where
      we need to return a property.
      
      While replacing 'property True' with it, I saw a case where we can
      simplify the use and thus reworked that check.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      2e0bb81d
    • Iustin Pop's avatar
      Add entire ConfigData serialisation tests · 9924d61e
      Iustin Pop authored
      
      Using the recently-added genArbitrary, we can now implement Arbitrary
      instances for even "huge" objects like Cluster, so let's use that to
      implement entire ConfigData serialisation tests.
      
      Note that, as we don't have yet proper types for some of the Params
      fields, we have to cheat via FlexibleInstances and
      TypeSynonymInstances, using either empty items or real arbitrary
      values.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      9924d61e
    • Iustin Pop's avatar
      Replace manual arbitrary instances with genArbitrary · 7022db83
      Iustin Pop authored
      
      There are a few more that could be replaces, once we start using
      appropriate (new)types.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      7022db83
    • Iustin Pop's avatar
      Introduce a helper for simple Arbitrary instances · 8492daa3
      Iustin Pop authored
      
      After getting really annoyed at yet another "<*> arbitrary", I thought
      that we should be able to automate this, at least for types which are
      simple enough and have already all the "prerequisites".
      
      Hence the new genArbitrary function and its helpers, which can:
      
      - build an arbitrary for Bounded types, using the regular "elements
        [minBound..maxBound]" (20 manually defined cases right now)
      - build an arbitrary instance for single-constructor data types,
        e.g. "data A = A x y z", using a simple "arbitrary = pure A <*>
        arbitrary <*> arbitrary <*> arbitrary"
      - build an arbitrary instance for multi-constructor data types, using
        "arbitrary = oneof [<arbitrary for each individual construct, per
        the previous>]"
      
      Both normal and record-based constructors are supported.
      
      It can also build arbitrary instances for new types and type synonyms,
      although for these last two I'm not so confident on the soundness of
      the instances.
      
      Note that this helper won't work for types which are not well behaved;
      for example, Node has the name as String not as FQDN, so our manually
      written arbitrary instance has just a few overrides as getFQDN instead
      of arbitrary, so we can't automate this particular type yet; this only
      means we get another push to use proper types, instead of primitive
      ones, for fields which have any kinds of restrictions ("what's good
      for arbitrary is good for regular code" too).
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      8492daa3
    • Iustin Pop's avatar
      Add Instance serialisations tests · ce93b4a0
      Iustin Pop authored
      
      This is not perfect, as for many of the parameters we don't have good
      Arbitrary instances, but is better than nothing.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      ce93b4a0
    • Iustin Pop's avatar
      Add a test helper for simple JSON serialisation testing · 63b068c1
      Iustin Pop authored
      
      While adding yet another JSON serialisation test, I realised that this
      can be trivially abstracted; hence this patch, replacing both simple
      versions (readJSON . showJSON == id) and the standard version (with
      different error messages) across the tests with a single function
      call.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      63b068c1
    • Iustin Pop's avatar
      Add unit test for serialisation of DiskLogicalId and Nodes · 8d2b6a12
      Iustin Pop authored
      
      Since the DiskLogicalId type is manually serialised/deserialised (see
      Objects.hs, `encodeDLid' and `decodeDLId'), let's add a test that
      checks that these are idempotent when combined.
      
      Since we're at it, let's add the same test for Node serialisation,
      which already has an Arbitrary instance.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      8d2b6a12
    • Iustin Pop's avatar
      Add unittests for the BasicTypes module · 1493a93b
      Iustin Pop authored
      
      This adds test properties for the various laws that the instances of
      Result should follow; I could not find (offline) laws about `mappend',
      but otherwise I implemented all laws that I could find.
      
      Note that we have to silence hlint warnings for the things we want to
      test, as otherwise hlint is all "this is already true based on the
      functor law, why 'fmap id' and not just 'id'?".
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      1493a93b
    • Iustin Pop's avatar
      Fixup test suite names · e09c1fa0
      Iustin Pop authored
      
      The names were not in a proper hierarchy, leading to inconsistencies
      about what they were actually tested.
      
      We change this by reproducing in the test names the relative hierarchy
      within the Ganeti directory, leading to nicer test suite names (in
      test-framework output).
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      e09c1fa0
    • Iustin Pop's avatar
      Simplify property and test case names · 20bc5360
      Iustin Pop authored
      
      Since we now have separate namespaces due to the multi-file split, we
      don't need to keep the name of the module in the property names, as we
      don't have so many potential conflicts anymore.
      
      We remove the group prefix handling from TestHelper and simply do a
      sed over all the test files, removing it from the function names.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      20bc5360
    • Iustin Pop's avatar
      Move Version.hs up from under HTools/ · 2997cb0a
      Iustin Pop authored
      
      This is another module that is generic, and not htools-specific.
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      2997cb0a
    • Iustin Pop's avatar
      Two tiny makefile fixes · 662de722
      Iustin Pop authored
      
      During the recent moves and renames, two things have slipped through,
      since I didn't run make check-local…
      
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
      662de722
  2. Sep 04, 2012
Loading