config_test.go 570 Bytes
Newer Older
1 2 3 4
package main

import (
  "encoding/json"
5
  "testing"
6 7 8
)

type FileConfig struct {
9
  Paths  []string          "json:paths"
10 11 12 13 14 15 16
  Fields map[string]string "json:fields"
}

func TestJSONLoading(t *testing.T) {
  var f File
  err := json.Unmarshal([]byte("{ \"paths\": [ \"/var/log/fail2ban.log\" ], \"fields\": { \"type\": \"fail2ban\" } }"), &f)

17 18 19 20 21 22 23 24 25 26 27 28
  if err != nil {
    t.Fatalf("json.Unmarshal failed")
  }
  if len(f.Paths) != 1 {
    t.FailNow()
  }
  if f.Paths[0] != "/var/log/fail2ban.log" {
    t.FailNow()
  }
  if f.Fields["type"] != "fail2ban" {
    t.FailNow()
  }
29
}