1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 23:42:20 +08:00
Files
kubo/repo/config/version_test.go

36 lines
904 B
Go

package config
import (
"encoding/json"
"strings"
"testing"
)
func TestAutoUpdateValues(t *testing.T) {
var tval struct {
AutoUpdate AutoUpdateSetting
}
tests := []struct {
input string
val AutoUpdateSetting
err error
}{
{`{"hello":123}`, AutoUpdateNever, nil}, // zero value
{`{"AutoUpdate": "never"}`, AutoUpdateNever, nil},
{`{"AutoUpdate": "patch"}`, AutoUpdatePatch, nil},
{`{"AutoUpdate": "minor"}`, AutoUpdateMinor, nil},
{`{"AutoUpdate": "major"}`, AutoUpdateMajor, nil},
{`{"AutoUpdate": "blarg"}`, AutoUpdateMinor, ErrUnknownAutoUpdateSetting},
}
for i, tc := range tests {
if err := json.NewDecoder(strings.NewReader(tc.input)).Decode(&tval); err != tc.err {
t.Fatalf("%d failed - got err %q wanted %v", i, err, tc.err)
}
if tval.AutoUpdate != tc.val {
t.Fatalf("%d failed - got val %q where we wanted %q", i, tval.AutoUpdate, tc.val)
}
}
}