Пример #1
0
func TestOpUnmarshal(t *testing.T) {
	t.Parallel()
	testCmd := bson.D{{"z", 1}, {"a", 1}}
	testQuery := bson.D{{"a", 1}, {"z", 1}}

	testCmdDoc := bson.D{
		{"ts", time.Unix(testTime, 0)},
		{"ns", "foo"},
		{"op", "command"},
		{"command", testCmd},
	}
	testQueryDoc := bson.D{
		{"ts", time.Unix(testTime, 0)},
		{"ns", "foo"},
		{"op", "query"},
		{"query", testQuery},
		{"ntoskip", 1},
		{"ntoreturn", 2},
	}

	// marshal to byte form so we can unmarshal into struct
	testCmdDocBytes, err := bson.Marshal(testCmdDoc)
	ensure.Nil(t, err)

	testQueryDocBytes, err := bson.Marshal(testQueryDoc)
	ensure.Nil(t, err)

	var testCmdOp, testQueryOp Op
	err = bson.Unmarshal(testCmdDocBytes, &testCmdOp)
	ensure.Nil(t, err)

	err = bson.Unmarshal(testQueryDocBytes, &testQueryOp)
	ensure.Nil(t, err)

	ensure.Subset(
		t,
		testCmdOp,
		Op{
			Timestamp:  time.Unix(testTime, 0),
			Ns:         "foo",
			Type:       Command,
			CommandDoc: testCmd,
		},
	)
	ensure.Subset(
		t,
		testQueryOp,
		Op{
			Timestamp: time.Unix(testTime, 0),
			Ns:        "foo",
			Type:      Query,
			QueryDoc:  testQuery,
			NToSkip:   1,
			NToReturn: 2,
		},
	)
}
Пример #2
0
func TestMetadata(t *testing.T) {
	m := NewMetadataStore()
	md0 := SnapshotMetadata{ReplicaID: "replset1_host1", ID: "1", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}}
	md1 := SnapshotMetadata{ReplicaID: "replset1_host1", ID: "2", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}}
	md2 := SnapshotMetadata{ReplicaID: "replset2_host2", ID: "1", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}}
	err := m.Add(NewLazySMFromM(&md0))
	ensure.Nil(t, err)
	err = m.Add(NewLazySMFromM(&md1))
	ensure.Nil(t, err)
	err = m.Add(NewLazySMFromM(&md2))
	ensure.Nil(t, err)

	ensure.SameElements(t, m.GetReplicaIDs(), []string{"replset1_host1", "replset2_host2"})

	lazyMD, err := m.getForReplica("replset1_host1")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, len(lazyMD), 2)
	mdRetrieved, err := lazyMD[0].Get()
	ensure.Nil(t, err)
	ensure.Subset(t, *mdRetrieved, SnapshotMetadata{ID: "1", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}})
	mdRetrieved, err = lazyMD[1].Get()
	ensure.Nil(t, err)
	ensure.Subset(t, *mdRetrieved, SnapshotMetadata{ID: "2", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}})

	lazyMD, err = m.getForReplica("replset2_host2")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, len(lazyMD), 1)
	mdRetrieved, err = lazyMD[0].Get()
	ensure.Nil(t, err)
	ensure.Subset(t, *mdRetrieved, SnapshotMetadata{ID: "1", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}})

	m.DeleteForReplicaByID("replset1_host1", "1")
	lazyMD, err = m.getForReplica("replset1_host1")
	ensure.Nil(t, err)
	// Both LazySnapshotMetadatas should still be in MetadataStore, but the first one should be marked for delete.
	ensure.DeepEqual(t, len(lazyMD), 2)
	ensure.True(t, lazyMD[0].DeleteMark)
	ensure.False(t, lazyMD[1].DeleteMark)

	mdRetrieved, err = lazyMD[1].Get()
	ensure.Nil(t, err)
	ensure.Subset(t, *mdRetrieved, SnapshotMetadata{ID: "2", Path: "/path/foo", Files: []File{{Name: "a"}, {Name: "b"}, {Name: "c"}}})
}
Пример #3
0
func TestSubsetStruct(t *testing.T) {
	var c capture
	ensure.Subset(&c, typ{}, typ{Answer: 42})
	c.Equal(t, `ensure_test.go:94: expected subset not found:
ACTUAL:
(ensure_test.typ) {
 Answer: (int) 0
}

EXPECTED SUBSET
(ensure_test.typ) {
 Answer: (int) 42
}`)
}
Пример #4
0
func TestIntegrateSingleResult(t *testing.T) {
	const target = "Ubuntu 14.10 Desktop 64bit ISO"
	client, err := NewClient(ClientRawURL(prodURL))
	ensure.Nil(t, err)
	actual, err := client.Search(target)
	ensure.Nil(t, err)
	ensure.Subset(t, actual, []Result{
		{
			Name:  "Ubuntu 14.10 Desktop 64bit ISO",
			Size:  "1.08 GB",
			Files: 1,
		},
	})
}
Пример #5
0
func TestComplex(t *testing.T) {
	t.Parallel()
	values := url.Values{}
	values.Add("status", "1")
	values.Add("server", "beta")
	values.Add("locale", "en_PI")
	expected := &rellenv.Env{
		Status: true,
		Env:    "beta",
	}
	env, _ := fromValues(t, values)
	ensure.Subset(t, env, expected)
	ensure.StringContains(t, env.SdkURL(), "en_PI")
}
Пример #6
0
func TestDefaultEnv(t *testing.T) {
	t.Parallel()
	env, _ := fromValues(t, url.Values{})
	ensure.Subset(t, env, defaultParser().Default())
}