Skip to content

Commit

Permalink
Simplify integration tests (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 authored Jul 5, 2024
1 parent 0a4b791 commit 1fc0646
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 268 deletions.
43 changes: 21 additions & 22 deletions pkg/kine/drivers/generic/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,66 @@ import (
"context"
"testing"

"github.com/onsi/gomega"
. "github.com/onsi/gomega"
)

func TestAllowAllPolicy_Admit(t *testing.T) {
g := gomega.NewGomegaWithT(t)
g := NewWithT(t)
policy := &allowAllPolicy{}

callOnFinish, err := policy.Admit(context.Background(), "get_size_sql")

g.Expect(err).To(gomega.BeNil())
g.Expect(callOnFinish).ToNot(gomega.BeNil())
g.Expect(err).To(BeNil())
g.Expect(callOnFinish).ToNot(BeNil())
}

func TestLimitPolicy_Admit(t *testing.T) {
g := gomega.NewGomegaWithT(t)
g := NewWithT(t)
policy := newLimitPolicy(false, 2)

// First two should succeed
done1, err := policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(done1).ToNot(gomega.BeNil())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(done1).ToNot(BeNil())
done2, err := policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(done2).ToNot(gomega.BeNil())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(done2).ToNot(BeNil())

// Third should be denied
done3, err := policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).To(gomega.HaveOccurred())
g.Expect(err).To(HaveOccurred())
// should still return a valid function as callers otherwise might segfault if they not check for nil.
g.Expect(done3).ToNot(gomega.BeNil())
g.Expect(done3).ToNot(BeNil())

// Complete a call - now the next query should be admitted again.
done1()
_, err = policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(done3).ToNot(gomega.BeNil())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(done3).ToNot(BeNil())
}

func TestLimitPolicy_Admit_OnlyCheckWriteQueries(t *testing.T) {
g := gomega.NewGomegaWithT(t)
g := NewWithT(t)
policy := newLimitPolicy(true, 2)

// Read queries should always succeed
_, err := policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
_, err = policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
_, err = policy.Admit(context.Background(), "get_size_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

// write queries should be evaluated, thus fail after second call
done1, err := policy.Admit(context.Background(), "insert_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
_, err = policy.Admit(context.Background(), "delete_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
_, err = policy.Admit(context.Background(), "fill_sql")
g.Expect(err).To(gomega.HaveOccurred())
g.Expect(err).To(HaveOccurred())

// Another write query should be possible after one is done
done1()
_, err = policy.Admit(context.Background(), "fill_sql")
g.Expect(err).ToNot(gomega.HaveOccurred())

g.Expect(err).ToNot(HaveOccurred())
}
2 changes: 1 addition & 1 deletion test/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestGet(t *testing.T) {
g.Expect(err).To(BeNil())
g.Expect(resp.Count).To(Equal(int64(0)))

updateRevision(ctx, g, client, key, lastModRev, "testValue2")
updateRev(ctx, g, client, key, lastModRev, "testValue2")

// Get the updated key
resp, err = client.Get(ctx, key, clientv3.WithCountOnly())
Expand Down
Loading

0 comments on commit 1fc0646

Please sign in to comment.