github.com/cilium/statedb@v0.3.2/testdata/db.txtar (about)

     1  #
     2  # This file is invoked by 'script_test.go' and tests the StateDB script commands 
     3  # defined in 'script.go'.
     4  #
     5  
     6  hive start
     7  
     8  # Show the registered tables
     9  db tables
    10  
    11  # Initialized
    12  db initialized
    13  db initialized test1
    14  db initialized test1 test2
    15  
    16  # Show (empty)
    17  db show test1
    18  db show test2
    19  
    20  # Insert
    21  db insert test1 obj1.yaml
    22  db insert test1 obj2.yaml
    23  db insert test2 obj2.yaml
    24  
    25  # Show (non-empty)
    26  db show test1
    27  grep ^ID.*Tags
    28  grep 1.*bar
    29  grep 2.*baz
    30  db show test2
    31  
    32  db show -format=table test1
    33  grep ^ID.*Tags
    34  grep 1.*bar
    35  grep 2.*baz
    36  
    37  db show -format=table -columns=Tags test1
    38  grep ^Tags$
    39  grep '^bar, foo$'
    40  grep '^baz, foo$'
    41  
    42  db show  -format=json test1
    43  grep ID.:1.*bar
    44  grep ID.:2.*baz
    45  
    46  db show  -format=yaml test1
    47  grep 'id: 1'
    48  grep 'id: 2'
    49  
    50  db show -format=yaml -o=test1_export.yaml test1
    51  cmp test1.yaml test1_export.yaml
    52  
    53  # Get
    54  db get test2 2
    55  db get -format=table test2 2
    56  grep '^ID.*Tags$'
    57  grep ^2.*baz
    58  db get -format=table -columns=Tags test2 2
    59  grep ^Tags$
    60  grep '^baz, foo$'
    61  db get -format=json test2 2
    62  db get -format=yaml test2 2
    63  db get -format=yaml -o=obj2_get.yaml test2 2
    64  cmp obj2.yaml obj2_get.yaml
    65  
    66  db get -index=tags -format=yaml -o=obj1_get.yaml test1 bar
    67  cmp obj1.yaml obj1_get.yaml
    68  
    69  # List
    70  db list -o=list.table test1 1
    71  cmp obj1.table list.table
    72  db list -o=list.table test1 2
    73  cmp obj2.table list.table
    74  
    75  db list -o=list.table -index=tags test1 bar
    76  cmp obj1.table list.table
    77  db list -o=list.table -index=tags test1 baz
    78  cmp obj2.table list.table
    79  db list -o=list.table -index=tags test1 foo
    80  cmp objs.table list.table
    81  
    82  db list -format=table -index=tags -columns=Tags test1 foo
    83  grep ^Tags$
    84  grep '^bar, foo$'
    85  grep '^baz, foo$'
    86  
    87  # Prefix
    88  # uint64 so can't really prefix search meaningfully, unless
    89  # FromString() accomodates partial keys.
    90  db prefix test1 1
    91  
    92  db prefix -o=prefix.table -index=tags test1 ba
    93  cmp objs.table prefix.table
    94  
    95  # LowerBound
    96  db lowerbound -o=lb.table test1 0
    97  cmp objs.table lb.table
    98  db lowerbound -o=lb.table test1 1
    99  cmp objs.table lb.table
   100  db lowerbound -o=lb.table test1 2
   101  cmp obj2.table lb.table
   102  db lowerbound -o=lb.table test1 3
   103  cmp empty.table lb.table
   104  
   105  # Compare
   106  db cmp test1 objs.table
   107  db cmp test1 objs_ids.table
   108  db cmp -grep=bar test1 obj1.table
   109  db cmp -grep=baz test1 obj2.table
   110  
   111  # Delete
   112  db delete test1 obj1.yaml
   113  db cmp test1 obj2.table
   114  
   115  db delete test1 obj2.yaml
   116  db cmp test1 empty.table
   117  
   118  # Delete with get
   119  db insert test1 obj1.yaml
   120  db cmp test1 obj1.table
   121  db get -delete test1 1
   122  db cmp test1 empty.table
   123  
   124  # Delete with prefix
   125  db insert test1 obj1.yaml
   126  db insert test1 obj2.yaml
   127  db cmp test1 objs.table
   128  db prefix -index=tags -delete test1 fo
   129  db cmp test1 empty.table
   130  
   131  # Delete with lowerbound
   132  db insert test1 obj1.yaml
   133  db insert test1 obj2.yaml
   134  db cmp test1 objs.table
   135  db lowerbound -index=id -delete test1 2
   136  db cmp test1 obj1.table
   137  
   138  # Tables
   139  db tables
   140  
   141  # ---------------------
   142  
   143  -- obj1.yaml --
   144  id: 1
   145  tags:
   146      - bar
   147      - foo
   148  -- obj2.yaml --
   149  id: 2
   150  tags:
   151      - baz
   152      - foo
   153  -- test1.yaml --
   154  id: 1
   155  tags:
   156      - bar
   157      - foo
   158  ---
   159  id: 2
   160  tags:
   161      - baz
   162      - foo
   163  -- objs.table --
   164  ID   Tags
   165  1    bar, foo
   166  2    baz, foo
   167  -- objs_ids.table --
   168  ID
   169  1
   170  2
   171  -- obj1.table --
   172  ID   Tags
   173  1    bar, foo
   174  -- obj2.table --
   175  ID   Tags
   176  2    baz, foo
   177  -- empty.table --
   178  ID   Tags