Skip to content

Conversation

@DancingLinks
Copy link
Contributor

  1. Add ipam/pool_test.go
  2. Add network/*test.go
  3. Using ginkgo test ipv6ipam

Copy link
Member

@mainred mainred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, and I need time for another look later.

})

Context("Create a new pool ID when the string is too long", func() {
It("Should create a pool ID by parsing the string", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should raise an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry my mistake

})
})

Context("", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may forget the context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be "When pool's epoch is less than the space's epoch and the pool is never in use"

})
})
})
) No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lost a newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, thx :)

Id: poolId,
IsIPv6: false,
}
ap, err := as.requestPool("", "", nil, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ap, err := as.requestPool("", "", nil, true)
ap, err := as.requestPool(poolId, "", nil, true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is to test requesting an ipv6 pool from an address space which only contain ipv4 pool, by only not assign the pool id it will enter the IP version matching "if branch".

})
})

Context("When as has pools with different addresses", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the struct name addressSpace or addressSpace object instead of the variable name in a context, so that we can understand from the plain text context better? we can discuss here.

Suggested change
Context("When as has pools with different addresses", func() {
Context("When a addressSpace has pools with different number of addresses", func() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree, please also edit all other affected cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, I also changed the ar to addressRecord

Id: "pool2",
Addresses: map[string]*addressRecord{},
}
as.Pools["pool2"].Addresses["ar"] = &addressRecord{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about we assign values from real cases, so that:

  1. it may detect more errors or better safeguard our code by walking through the code with real values.
  2. it can help people understand the structure of the code even without running env.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, very helpful suggestion!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Describe("Test releasePool", func() {
Context("When pool not found", func() {
It("Should return error", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It("Should return error", func() {
It("Should return an error", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Should raise an error?" seems better?

})

Context("", func() {
It("", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may forget the expectation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, it should be "When pool's epoch is less than the space's epoch and pool is never in use"

})
})

Context("When ar is ubhealthy", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context("When ar is ubhealthy", func() {
Context("When an addressPool is unhealthy", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "When addressRecords are unhealthy" ?

Comment on lines 59 to 61
if runtime.GOOS == windows {
kubeConfigPath = defaultWindowsKubeConfigFilePath
} else {
kubeConfigPath = defaultLinuxKubeConfigFilePath
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Less, the tidy, and define kubeConfigPath when being used here.

Suggested change
if runtime.GOOS == windows {
kubeConfigPath = defaultWindowsKubeConfigFilePath
} else {
kubeConfigPath = defaultLinuxKubeConfigFilePath
}
kubeConfigPath := defaultLinuxKubeConfigFilePath
if runtime.GOOS == windows {
kubeConfigPath = defaultWindowsKubeConfigFilePath
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

},
}
Context("When node doesn't have IPv6 subnet", func() {
It("Expected to fail IPv6 IP retrieval", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It("Expected to fail IPv6 IP retrieval", func() {
It("Should fail to retrieve the IPv6 address", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

})

Describe("Test updateEndpoint", func() {
Context("", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, I forget adding this test case.

Comment on lines 183 to 193
testData := map[string]string{
"nginx-deployment-5c689d88bb": "nginx",
"nginx-deployment-5c689d88bb-qwq47": "nginx-deployment",
"nginx": "nginx",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testData := map[string]string{
"nginx-deployment-5c689d88bb": "nginx",
"nginx-deployment-5c689d88bb-qwq47": "nginx-deployment",
"nginx": "nginx",
}
testData := map[string]string{
"nginx-deployment-5c689d88bb": "nginx",
"nginx-deployment-5c689d88bb-qwq47": "nginx-deployment",
"nginx" : "nginx",
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you need a lint tool. Could you please run gofmt or more in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from the origin test cases, I'll format it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we need a lint check in CI.

Copy link
Member

@mainred mainred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your effort, and the values borrowed from real cases impressed me a lot.

})
})

Context("When IfName is not match", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context("When IfName is not match", func() {
Context("When the requested interface name does not exist", func() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you resolve this also?

@DancingLinks
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 543 in repo Azure/azure-container-networking

@tamilmani1989 tamilmani1989 changed the title Network test Improving and adding CNI unit tests Apr 16, 2020
Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this PR. Appreciate your effort. Left some comments


Describe("Test newIPv6IpamSource", func() {

Context("When using windows environment", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why context is windows env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "When creating with current environment", thx

)

func TestManagerIpv6Ipam(t *testing.T) {
RegisterFailHandler(Fail)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where these functions are defined? can you add comment as well about these functions and what it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined in pkg Gpmega. RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails the fail handler passed into RegisterFailHandler is called.

})
})

Context("When test with a specified address", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test without requesting address explicitly

})
})

Context("Create a new pool ID when the string is too long", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new pool ID when string format is incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, thx

})
})

Context("When SandboxKey now in use", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context("When SandboxKey now in use", func() {
Context("When SandboxKey not in use", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont

_ = Describe("Test Network", func() {

Describe("Test newExternalInterface", func() {
Context("When external interface alread exists", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context("When external interface alread exists", func() {
Context("When external interface already exists", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Expect(nm.TimeStamp).To(Equal(time.Time{}))
})
})
Context("When store.Write error", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context("When store.Write error", func() {
Context("When store.Write returns error", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})
})

Context("When ifName is empty", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldnt understand this? what you mean by ifName is empty? Can you add a proper description of this test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"When ifName is not specified"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update description saying "When ifName not specifed in GetNumberofEndpoints"


Describe("Test newExternalInterface", func() {
Context("When external interface alread exists", func() {
It("Should return nil", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to check if nm.ExternalInterfaces is updated with "subnet" right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, very good suggestion!

Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see some comments are unaddressed still..address those

})
})

Context("When IfName is not match", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you resolve this also?

})
})

Context("When pool's epoch is less than the space's epoch and pool is never in use", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefCount: 1 so it mean pool in use by one entity and should be deleted. If pool not in use, delete should fail

})
})

Context("When ifName is empty", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update description saying "When ifName not specifed in GetNumberofEndpoints"

@matmerr
Copy link
Member

matmerr commented May 11, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@codecov
Copy link

codecov bot commented May 11, 2020

Codecov Report

Merging #543 into master will decrease coverage by 10.25%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master     #543       +/-   ##
===========================================
- Coverage   49.22%   38.97%   -10.26%     
===========================================
  Files          28       42       +14     
  Lines        3437     5047     +1610     
===========================================
+ Hits         1692     1967      +275     
- Misses       1455     2811     +1356     
+ Partials      290      269       -21     

@tamilmani1989
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tamilmani1989 tamilmani1989 merged commit 7b5e817 into Azure:master Jun 26, 2020
pjohnst5 pushed a commit to pjohnst5/azure-container-networking that referenced this pull request Jul 9, 2020
* Add ipam/pool_test.go & add network/*test.go

* add testing ./network/ in Makefile

* fix context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants