github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/repo/config/version_test.go (about)

     1  package config
     2  
     3  import (
     4  	"encoding/json"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestAutoUpdateValues(t *testing.T) {
    10  	var tval struct {
    11  		AutoUpdate AutoUpdateSetting
    12  	}
    13  	tests := []struct {
    14  		input string
    15  		val   AutoUpdateSetting
    16  		err   error
    17  	}{
    18  		{`{"hello":123}`, AutoUpdateNever, nil}, // zero value
    19  		{`{"AutoUpdate": "never"}`, AutoUpdateNever, nil},
    20  		{`{"AutoUpdate": "patch"}`, AutoUpdatePatch, nil},
    21  		{`{"AutoUpdate": "minor"}`, AutoUpdateMinor, nil},
    22  		{`{"AutoUpdate": "major"}`, AutoUpdateMajor, nil},
    23  		{`{"AutoUpdate": "blarg"}`, AutoUpdateMinor, ErrUnknownAutoUpdateSetting},
    24  	}
    25  
    26  	for i, tc := range tests {
    27  		if err := json.NewDecoder(strings.NewReader(tc.input)).Decode(&tval); err != tc.err {
    28  			t.Fatalf("%d failed - got err %q wanted %v", i, err, tc.err)
    29  		}
    30  
    31  		if tval.AutoUpdate != tc.val {
    32  			t.Fatalf("%d failed - got val %q where we wanted %q", i, tval.AutoUpdate, tc.val)
    33  		}
    34  	}
    35  }