 
       gobgp.addPath family: 'ipv4-unicast', path
 
-      table = global_rib()
-      expect(table.length).to.equal 1
-      expect(table[0]['prefix']).to.equal PREFIX
+      prefixes = global_rib(PREFIX)
+      expect(prefixes.length).to.equal 1
 
       expect(communities(PREFIX)).to.eql [4294967042]
 


      gobgp.modPath family: 'ipv4-unicast', PREFIX

      table = global_rib()
      expect(table.length).to.equal 1
      expect(table[0]['prefix']).to.equal PREFIX

    it 'withdraws a route', ->
      exec "gobgp global rib add #{PREFIX}"

exec   = require('child_process').execSync

describe 'gobgp-node', ->
  global_rib = (prefix) ->
    table = JSON.parse(exec('gobgp -j global rib'))
    if prefix
      table[prefix]
    else
      table

  flowspec_rib = (prefix) ->
    table = JSON.parse(exec('gobgp -j global rib -a ipv4-flowspec'))
    if prefix
      table[prefix]
    else
      table

  communities = (prefix) ->
    paths = global_rib(prefix)
    return if paths.empty?

    comms = paths[0]['attrs'].filter (i) -> i['type']==8
    return comms[0]['communities']

  PREFIX = '10.0.0.0/24'
  FLOWSPEC_PREFIX = "match source #{PREFIX} then rate-limit 10000"
  FLOWSPEC_JSON_PREFIX = "[source:#{PREFIX}]"

  beforeEach ->
    exec "gobgp global rib del #{PREFIX}"
