func TestAppv1Supported(t *testing.T) {
	cases := []struct {
		proto    string
		expected bool
	}{
		{"appv1", true},
		{"invalid", false},
	}

	var appv1 snapshot.UpdateServiceSnapshotAppv1
	for _, c := range cases {
		assert.Equal(t, c.expected, appv1.Supported(c.proto), "Fail to get supported status")
	}
}
func TestAppv1New(t *testing.T) {
	cases := []struct {
		id       string
		url      string
		expected bool
	}{
		{"id", "url", true},
		{"", "url", false},
		{"id", "", false},
	}

	var appv1 snapshot.UpdateServiceSnapshotAppv1
	for _, c := range cases {
		info := snapshot.SnapshotInputInfo{CallbackID: c.id, DataURL: c.url}
		_, err := appv1.New(info)
		assert.Equal(t, c.expected, err == nil, "Fail to create new snapshot appv1")
	}
}
func TestAppv1Process(t *testing.T) {
	for n, _ := range cbMap {
		delete(cbMap, n)
	}

	cases := []struct {
		id         string
		url        string
		cb         snapshot.Callback
		pExpected  bool
		idExpected bool
		md5        string
	}{
		{"1", "snapshot/testmd5", testCB, true, true, "ffe7c736f2aa54531ac6430e3cbf2545"},
		{"2", "snapshot/invalid", testCB, true, true, ""},
		{"3", "snapshot/testmd5", testCB, false, false, ""},
		{"4", "snapshot/testmd5", nil, true, false, ""},
	}

	var appv1 snapshot.UpdateServiceSnapshotAppv1
	_, path, _, _ := runtime.Caller(0)
	dir := filepath.Join(filepath.Dir(path), "testdata")

	for _, c := range cases {
		info := snapshot.SnapshotInputInfo{CallbackID: c.id, DataURL: filepath.Join(dir, c.url), CallbackFunc: c.cb}
		a, _ := appv1.New(info)
		err := a.Process()
		assert.Equal(t, c.pExpected, err == nil, "Fail to get correct process output")

		data, ok := cbMap[c.id]
		assert.Equal(t, c.idExpected, ok, "Fail to call cb")
		if ok {
			assert.Equal(t, c.md5, fmt.Sprintf("%x", data.Data), "Fail to call cb md5")
		}
	}
}