main_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2016 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. package main
  5. import (
  6. "math"
  7. "testing"
  8. "notabug.org/themusicgod1/goarista/test"
  9. "github.com/openconfig/reference/rpc/openconfig"
  10. )
  11. func TestParseValue(t *testing.T) { // Because parsing JSON sucks.
  12. testcases := []struct {
  13. input string
  14. expected interface{}
  15. }{
  16. {"42", []interface{}{int64(42)}},
  17. {"-42", []interface{}{int64(-42)}},
  18. {"42.42", []interface{}{float64(42.42)}},
  19. {"-42.42", []interface{}{float64(-42.42)}},
  20. {`"foo"`, []interface{}(nil)},
  21. {"9223372036854775807", []interface{}{int64(math.MaxInt64)}},
  22. {"-9223372036854775808", []interface{}{int64(math.MinInt64)}},
  23. {"9223372036854775808", []interface{}{uint64(math.MaxInt64) + 1}},
  24. {"[1,3,5,7,9]", []interface{}{int64(1), int64(3), int64(5), int64(7), int64(9)}},
  25. {"[1,9223372036854775808,0,-9223372036854775808]", []interface{}{
  26. int64(1),
  27. uint64(math.MaxInt64) + 1,
  28. int64(0),
  29. int64(math.MinInt64)},
  30. },
  31. }
  32. for i, tcase := range testcases {
  33. actual := parseValue(&openconfig.Update{
  34. Value: &openconfig.Value{
  35. Value: []byte(tcase.input),
  36. },
  37. })
  38. if d := test.Diff(tcase.expected, actual); d != "" {
  39. t.Errorf("#%d: %s: %#v vs %#v", i, d, tcase.expected, actual)
  40. }
  41. }
  42. }