github.com/mckael/restic@v0.8.3/internal/restic/blob_test.go (about)

     1  package restic
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  )
     7  
     8  var blobTypeJSON = []struct {
     9  	t   BlobType
    10  	res string
    11  }{
    12  	{DataBlob, `"data"`},
    13  	{TreeBlob, `"tree"`},
    14  }
    15  
    16  func TestBlobTypeJSON(t *testing.T) {
    17  	for _, test := range blobTypeJSON {
    18  		// test serialize
    19  		buf, err := json.Marshal(test.t)
    20  		if err != nil {
    21  			t.Error(err)
    22  			continue
    23  		}
    24  		if test.res != string(buf) {
    25  			t.Errorf("want %q, got %q", test.res, string(buf))
    26  			continue
    27  		}
    28  
    29  		// test unserialize
    30  		var v BlobType
    31  		err = json.Unmarshal([]byte(test.res), &v)
    32  		if err != nil {
    33  			t.Error(err)
    34  			continue
    35  		}
    36  		if test.t != v {
    37  			t.Errorf("want %v, got %v", test.t, v)
    38  			continue
    39  		}
    40  	}
    41  }