Skip to content

Commit

Permalink
Update E2E tests for policies/profiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Jul 11, 2017
1 parent 12ecd52 commit b150de5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 8 deletions.
33 changes: 29 additions & 4 deletions lib/client/policy_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ var policySpec1 = api.PolicySpec{
Selector: "thing == 'value'",
}

// When reading back, the rules should have been updated to the newer format.
var policySpec1AfterRead = api.PolicySpec{
Order: &order1,
IngressRules: []api.Rule{testutils.InRule1AfterRead, testutils.InRule2AfterRead},
EgressRules: []api.Rule{testutils.EgressRule1AfterRead, testutils.EgressRule2AfterRead},
Selector: "thing == 'value'",
}

var policySpec2 = api.PolicySpec{
Order: &order2,
IngressRules: []api.Rule{testutils.InRule2, testutils.InRule1},
Expand All @@ -63,10 +71,19 @@ var policySpec2 = api.PolicySpec{
DoNotTrack: true,
}

// When reading back, the rules should have been updated to the newer format.
var policySpec2AfterRead = api.PolicySpec{
Order: &order2,
IngressRules: []api.Rule{testutils.InRule2AfterRead, testutils.InRule1AfterRead},
EgressRules: []api.Rule{testutils.EgressRule2AfterRead, testutils.EgressRule1AfterRead},
Selector: "thing2 == 'value2'",
DoNotTrack: true,
}

var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2, func(config api.CalicoAPIConfig) {

DescribeTable("Policy e2e tests",
func(meta1, meta2 api.PolicyMetadata, spec1, spec2 api.PolicySpec) {
func(meta1, meta2 api.PolicyMetadata, spec1, spec2, spec1AfterRead, spec2AfterRead api.PolicySpec) {
c := testutils.CreateCleanClient(config)
By("Updating the policy before it is created")
_, outError := c.Policies().Update(&api.Policy{Metadata: meta1, Spec: spec1})
Expand Down Expand Up @@ -95,8 +112,8 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2
// Should match spec1 & outPolicy1 and outPolicy2 & spec2 and errors to be nil.
Expect(outError1).NotTo(HaveOccurred())
Expect(outError2).NotTo(HaveOccurred())
Expect(outPolicy1.Spec).To(Equal(spec1))
Expect(outPolicy2.Spec).To(Equal(spec2))
Expect(outPolicy1.Spec).To(Equal(spec1AfterRead))
Expect(outPolicy2.Spec).To(Equal(spec2AfterRead))

By("Update, Get and compare")

Expand All @@ -109,7 +126,7 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2

// Assert the Spec for policy with meta1 matches spec2 and no error.
Expect(outError1).NotTo(HaveOccurred())
Expect(outPolicy1.Spec).To(Equal(spec2))
Expect(outPolicy1.Spec).To(Equal(spec2AfterRead))

By("List all the policies and compare")

Expand Down Expand Up @@ -183,6 +200,8 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2
api.PolicyMetadata{Name: "policy.1"},
policySpec1,
policySpec2,
policySpec1AfterRead,
policySpec2AfterRead,
),

// Test 2: Pass one fully populated PolicySpec and another empty PolicySpec and expect the series of operations to succeed.
Expand All @@ -191,6 +210,8 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2
api.PolicyMetadata{Name: "policy.1"},
policySpec1,
api.PolicySpec{},
policySpec1AfterRead,
api.PolicySpec{},
),

// Test 3: Pass one partially populated PolicySpec and another fully populated PolicySpec and expect the series of operations to succeed.
Expand All @@ -201,6 +222,10 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2
Selector: "has(myLabel-8.9/88-._9)",
},
policySpec2,
api.PolicySpec{
Selector: "has(myLabel-8.9/88-._9)",
},
policySpec2AfterRead,
),
)
})
28 changes: 24 additions & 4 deletions lib/client/profile_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,30 @@ var profileSpec1 = api.ProfileSpec{
IngressRules: []api.Rule{testutils.InRule1, testutils.InRule2},
EgressRules: []api.Rule{testutils.EgressRule1, testutils.EgressRule2},
}

// When reading back, the rules should have been updated to the newer format.
var profileSpec1AfterRead = api.ProfileSpec{
IngressRules: []api.Rule{testutils.InRule1AfterRead, testutils.InRule2AfterRead},
EgressRules: []api.Rule{testutils.EgressRule1AfterRead, testutils.EgressRule2AfterRead},
}
var tags1 = []string{"profile1-tag1", "profile1-tag2"}

var profileSpec2 = api.ProfileSpec{
IngressRules: []api.Rule{testutils.InRule2, testutils.InRule1},
EgressRules: []api.Rule{testutils.EgressRule2, testutils.EgressRule1},
}

// When reading back, the rules should have been updated to the newer format.
var profileSpec2AfterRead = api.ProfileSpec{
IngressRules: []api.Rule{testutils.InRule2AfterRead, testutils.InRule1AfterRead},
EgressRules: []api.Rule{testutils.EgressRule2AfterRead, testutils.EgressRule1AfterRead},
}
var tags2 = []string{"profile2-tag1", "profile2-tag2"}

var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV2, func(config api.CalicoAPIConfig) {

DescribeTable("Profile e2e tests",
func(meta1, meta2 api.ProfileMetadata, spec1, spec2 api.ProfileSpec) {
func(meta1, meta2 api.ProfileMetadata, spec1, spec2, spec1AfterRead, spec2AfterRead api.ProfileSpec) {
c := testutils.CreateCleanClient(config)

By("Updating the profile before it is created")
Expand Down Expand Up @@ -90,8 +102,8 @@ var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV
// Should match spec1 & outProfile1 and outProfile2 & spec2 and errors to be nil.
Expect(outError1).NotTo(HaveOccurred())
Expect(outError2).NotTo(HaveOccurred())
Expect(outProfile1.Spec).To(Equal(spec1))
Expect(outProfile2.Spec).To(Equal(spec2))
Expect(outProfile1.Spec).To(Equal(spec1AfterRead))
Expect(outProfile2.Spec).To(Equal(spec2AfterRead))

By("Update, Get and compare")

Expand All @@ -104,7 +116,7 @@ var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV

// Assert the Spec for profile with meta1 matches spec2 and no error.
Expect(outError1).NotTo(HaveOccurred())
Expect(outProfile1.Spec).To(Equal(spec2))
Expect(outProfile1.Spec).To(Equal(spec2AfterRead))

By("List all the profiles and compare")

Expand Down Expand Up @@ -192,6 +204,8 @@ var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV
},
profileSpec1,
profileSpec2,
profileSpec1AfterRead,
profileSpec2AfterRead,
),

// Test 2: Pass one fully populated ProfileSpec and another empty ProfileSpec and expect the series of operations to succeed.
Expand All @@ -213,6 +227,8 @@ var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV
},
profileSpec1,
api.ProfileSpec{},
profileSpec1AfterRead,
api.ProfileSpec{},
),

// Test 3: Pass one partially populated ProfileSpec and another fully populated ProfileSpec and expect the series of operations to succeed.
Expand All @@ -235,6 +251,10 @@ var _ = testutils.E2eDatastoreDescribe("Profile tests", testutils.DatastoreEtcdV
IngressRules: []api.Rule{testutils.InRule1},
},
profileSpec2,
api.ProfileSpec{
IngressRules: []api.Rule{testutils.InRule1AfterRead},
},
profileSpec2AfterRead,
),
)
})
48 changes: 48 additions & 0 deletions lib/testutils/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ var InRule1 = api.Rule{
},
}

var InRule1AfterRead = api.Rule{
Action: "allow",
IPVersion: &ipv4,
Protocol: &strProtocol1,
ICMP: &icmp1,
Source: api.EntityRule{
Tag: "tag1",
Nets: []*net.IPNet{&cidr1},
Selector: "label1 == 'value1'",
},
}

var InRule2 = api.Rule{
Action: "deny",
IPVersion: &ipv6,
Expand All @@ -63,6 +75,18 @@ var InRule2 = api.Rule{
},
}

var InRule2AfterRead = api.Rule{
Action: "deny",
IPVersion: &ipv6,
Protocol: &numProtocol1,
ICMP: &icmp1,
Source: api.EntityRule{
Tag: "tag2",
Nets: []*net.IPNet{&cidrv61},
Selector: "has(label2)",
},
}

var EgressRule1 = api.Rule{
Action: "pass",
IPVersion: &ipv4,
Expand All @@ -75,6 +99,18 @@ var EgressRule1 = api.Rule{
},
}

var EgressRule1AfterRead = api.Rule{
Action: "pass",
IPVersion: &ipv4,
Protocol: &numProtocol1,
ICMP: &icmp1,
Source: api.EntityRule{
Tag: "tag3",
Nets: []*net.IPNet{&cidr2},
Selector: "all()",
},
}

var EgressRule2 = api.Rule{
Action: "allow",
IPVersion: &ipv6,
Expand All @@ -86,3 +122,15 @@ var EgressRule2 = api.Rule{
Selector: "label2 == '1234'",
},
}

var EgressRule2AfterRead = api.Rule{
Action: "allow",
IPVersion: &ipv6,
Protocol: &strProtocol2,
ICMP: &icmp1,
Source: api.EntityRule{
Tag: "tag4",
Nets: []*net.IPNet{&cidrv62},
Selector: "label2 == '1234'",
},
}

0 comments on commit b150de5

Please sign in to comment.