mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Add tests for invalid container manifests.
This commit is contained in:
parent
fecfe23ed1
commit
ce572050a8
@ -47,6 +47,53 @@ func TestExtractFromHttpBadness(t *testing.T) {
|
|||||||
expectEmptyChannel(t, ch)
|
expectEmptyChannel(t, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExtractInvalidManifest(t *testing.T) {
|
||||||
|
var testCases = []struct {
|
||||||
|
desc string
|
||||||
|
manifests interface{}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "No version",
|
||||||
|
manifests: []api.ContainerManifest{{Version: ""}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Invalid version",
|
||||||
|
manifests: []api.ContainerManifest{{Version: "v1betta2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Invalid volume name",
|
||||||
|
manifests: []api.ContainerManifest{
|
||||||
|
{Version: "v1beta1", Volumes: []api.Volume{{Name: "_INVALID_"}}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Duplicate volume names",
|
||||||
|
manifests: []api.ContainerManifest{
|
||||||
|
{
|
||||||
|
Version: "v1beta1",
|
||||||
|
Volumes: []api.Volume{{Name: "repeated"}, {Name: "repeated"}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
data, err := json.Marshal(testCase.manifests)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s: Some weird json problem: %v", testCase.desc, err)
|
||||||
|
}
|
||||||
|
fakeHandler := util.FakeHandler{
|
||||||
|
StatusCode: 200,
|
||||||
|
ResponseBody: string(data),
|
||||||
|
}
|
||||||
|
testServer := httptest.NewServer(&fakeHandler)
|
||||||
|
ch := make(chan interface{}, 1)
|
||||||
|
c := SourceURL{testServer.URL, ch}
|
||||||
|
if err := c.extractFromURL(); err == nil {
|
||||||
|
t.Errorf("%s: Expected error", testCase.desc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExtractFromHTTP(t *testing.T) {
|
func TestExtractFromHTTP(t *testing.T) {
|
||||||
var testCases = []struct {
|
var testCases = []struct {
|
||||||
desc string
|
desc string
|
||||||
|
Loading…
Reference in New Issue
Block a user