github.com/psiphon-inc/goarista@v0.0.0-20160825065156-d002785f4c67/cmd/octsdb/main_test.go (about)

     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  
     5  package main
     6  
     7  import (
     8  	"math"
     9  	"testing"
    10  
    11  	"github.com/aristanetworks/goarista/openconfig"
    12  	"github.com/aristanetworks/goarista/test"
    13  )
    14  
    15  func TestParseValue(t *testing.T) { // Because parsing JSON sucks.
    16  	testcases := []struct {
    17  		input    string
    18  		expected interface{}
    19  	}{
    20  		{"42", int64(42)},
    21  		{"-42", int64(-42)},
    22  		{"42.42", float64(42.42)},
    23  		{"-42.42", float64(-42.42)},
    24  		{`"foo"`, nil},
    25  		{"9223372036854775807", int64(math.MaxInt64)},
    26  		{"-9223372036854775808", int64(math.MinInt64)},
    27  		{"9223372036854775808", uint64(math.MaxInt64) + 1},
    28  	}
    29  	for i, tcase := range testcases {
    30  		actual := parseValue(&openconfig.Update{
    31  			Value: &openconfig.Value{
    32  				Value: []byte(tcase.input),
    33  			},
    34  		})
    35  		if d := test.Diff(tcase.expected, actual); d != "" {
    36  			t.Errorf("#%d: %s: %#v vs %#v", i, d, tcase.expected, actual)
    37  		}
    38  	}
    39  }