github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/types/capacity/capacity_test.go (about)

     1  package capacity
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"testing"
     7  )
     8  
     9  // Roundtrip some examples
    10  func TestCapacityMarshal(t *testing.T) {
    11  	s := []string{
    12  		`{"CapacityUnits":1,"TableName":"mytable"}`,
    13  		`{"CapacityUnits":1.01,"TableName":"mytable","Table":{"CapacityUnits":2.01}}`,
    14  		`{"CapacityUnits":1.01,"TableName":"mytable","Table":{"CapacityUnits":2.01},"LocalSecondaryIndexes":{"mylsi":{"CapacityUnits":10.1}},"GlobalSecondaryIndexes":{"mygsi0":{"CapacityUnits":11.11},"mygsi1":{"CapacityUnits":10.1}}}`,
    15  	}
    16  	for i, v := range s {
    17  		var a ConsumedCapacity
    18  		um_err := json.Unmarshal([]byte(v), &a)
    19  		if um_err != nil {
    20  			t.Errorf("cannot unmarshal\n")
    21  		}
    22  
    23  		json, jerr := json.Marshal(a)
    24  		if jerr != nil {
    25  			t.Errorf("cannot marshal\n")
    26  		}
    27  		if len(s[i]) != len(string(json)) {
    28  			e := fmt.Sprintf("%s\n%s\nshould be same",s[i],string(json))
    29  			t.Errorf(e)
    30  		}
    31  	}
    32  }