From 6308382af9fb3dd36376dd0dd4df2ace3bc427fb Mon Sep 17 00:00:00 2001 From: "shanbo.lkw" Date: Tue, 31 Jul 2018 10:35:35 +0800 Subject: [PATCH 1/3] Test_imageToImage --- cri/v1alpha1/cri_utils_test.go | 251 +++++++++++++++++++++++++++++++-- 1 file changed, 240 insertions(+), 11 deletions(-) diff --git a/cri/v1alpha1/cri_utils_test.go b/cri/v1alpha1/cri_utils_test.go index 01f39c393..81610fe82 100644 --- a/cri/v1alpha1/cri_utils_test.go +++ b/cri/v1alpha1/cri_utils_test.go @@ -282,7 +282,7 @@ func Test_makeSandboxPouchConfig(t *testing.T) { want *apitypes.ContainerCreateConfig wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -342,7 +342,7 @@ func Test_toCriSandbox(t *testing.T) { want *runtime.PodSandbox wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -558,7 +558,7 @@ func Test_makeContainerName(t *testing.T) { args args want string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -579,7 +579,7 @@ func Test_modifyContainerNamespaceOptions(t *testing.T) { name string args args }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -600,7 +600,7 @@ func Test_applyContainerSecurityContext(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -628,7 +628,7 @@ func TestCriManager_updateCreateConfig(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -653,7 +653,7 @@ func Test_toCriContainer(t *testing.T) { want *runtime.Container wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -680,7 +680,236 @@ func Test_imageToCriImage(t *testing.T) { want *runtime.Image wantErr bool }{ - // TODO: Add test cases. + { + "case1", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "xiaoming", + }, + ID: "1", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 1024, + }, + }, + &runtime.Image{ + Id: "1", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 1024, + Uid: &runtime.Int64Value{Value: 0}, + Username: "xiaoming", + }, + false, + }, + { + "case2", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456", + }, + ID: "1", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 1024, + }, + }, + &runtime.Image{ + Id: "1", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 1024, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case3", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "1", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 1024, + }, + }, + &runtime.Image{ + Id: "1", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 1024, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case4", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "1", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 1024, + }, + }, + &runtime.Image{ + Id: "1", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 1024, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case5", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "1", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 2048, + }, + }, + &runtime.Image{ + Id: "1", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 2048, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case6", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "abc", + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 2048, + }, + }, + &runtime.Image{ + Id: "abc", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"asdlkfej", "vwoeifo"}, + Size_: 2048, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case7", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "abc", + RepoDigests: []string{"1238", "4820940"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 2048, + }, + }, + &runtime.Image{ + Id: "abc", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"1238", "4820940"}, + Size_: 2048, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case8", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "123456:dev", + }, + ID: "abc", + RepoDigests: []string{"1238", "4820940"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: -2048, + }, + }, + &runtime.Image{ + Id: "abc", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"1238", "4820940"}, + Size_: 18446744073709549568, + Uid: &runtime.Int64Value{Value: int64(123456)}, + Username: "", + }, + false, + }, + { + "case9", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "-123456:dev", + }, + ID: "abc", + RepoDigests: []string{"1238", "4820940"}, + RepoTags: []string{"sldkfeio", "civlme"}, + Size: 2048, + }, + }, + &runtime.Image{ + Id: "abc", + RepoTags: []string{"sldkfeio", "civlme"}, + RepoDigests: []string{"1238", "4820940"}, + Size_: 2048, + Uid: &runtime.Int64Value{Value: int64(-123456)}, + Username: "", + }, + false, + }, + { + "case10", + args{ + &apitypes.ImageInfo{ + Config: &apitypes.ContainerConfig{ + User: "", + }, + ID: "abc", + RepoDigests: []string{"1238", "4820940"}, + RepoTags: []string{"xcuvk23", "cuvkwej23095489"}, + Size: 2048, + }, + }, + &runtime.Image{ + Id: "abc", + RepoTags: []string{"xcuvk23", "cuvkwej23095489"}, + RepoDigests: []string{"1238", "4820940"}, + Size_: 2048, + Uid: &runtime.Int64Value{Value: int64(0)}, + Username: "", + }, + false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -711,7 +940,7 @@ func TestCriManager_ensureSandboxImageExists(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -736,7 +965,7 @@ func Test_getUserFromImageUser(t *testing.T) { want *int64 want1 string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -760,7 +989,7 @@ func Test_parseUserFromImageUser(t *testing.T) { args args want string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From cf50f5c24a62ea76b8216a2ed1c9be41a6188d08 Mon Sep 17 00:00:00 2001 From: "shanbo.lkw" Date: Tue, 31 Jul 2018 11:08:15 +0800 Subject: [PATCH 2/3] Test_imageToCriImage --- cri/v1alpha1/cri_utils_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cri/v1alpha1/cri_utils_test.go b/cri/v1alpha1/cri_utils_test.go index 81610fe82..1d25b058f 100644 --- a/cri/v1alpha1/cri_utils_test.go +++ b/cri/v1alpha1/cri_utils_test.go @@ -282,7 +282,7 @@ func Test_makeSandboxPouchConfig(t *testing.T) { want *apitypes.ContainerCreateConfig wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -342,7 +342,7 @@ func Test_toCriSandbox(t *testing.T) { want *runtime.PodSandbox wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -558,7 +558,7 @@ func Test_makeContainerName(t *testing.T) { args args want string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -579,7 +579,7 @@ func Test_modifyContainerNamespaceOptions(t *testing.T) { name string args args }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -600,7 +600,7 @@ func Test_applyContainerSecurityContext(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -628,7 +628,7 @@ func TestCriManager_updateCreateConfig(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -653,7 +653,7 @@ func Test_toCriContainer(t *testing.T) { want *runtime.Container wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -940,7 +940,7 @@ func TestCriManager_ensureSandboxImageExists(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -965,7 +965,7 @@ func Test_getUserFromImageUser(t *testing.T) { want *int64 want1 string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -989,7 +989,7 @@ func Test_parseUserFromImageUser(t *testing.T) { args args want string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From d7cd43a01775ab82413551b172fa2b8701a72154 Mon Sep 17 00:00:00 2001 From: "shanbo.lkw" Date: Tue, 31 Jul 2018 11:41:18 +0800 Subject: [PATCH 3/3] Test_imageToCriImage Signed-off-by: shanbo.lkw --- cri/v1alpha1/cri_utils_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cri/v1alpha1/cri_utils_test.go b/cri/v1alpha1/cri_utils_test.go index 1d25b058f..019ef1c7a 100644 --- a/cri/v1alpha1/cri_utils_test.go +++ b/cri/v1alpha1/cri_utils_test.go @@ -896,13 +896,13 @@ func Test_imageToCriImage(t *testing.T) { }, ID: "abc", RepoDigests: []string{"1238", "4820940"}, - RepoTags: []string{"xcuvk23", "cuvkwej23095489"}, + RepoTags: []string{"xcuvk2", "cuvkwej23095489"}, Size: 2048, }, }, &runtime.Image{ Id: "abc", - RepoTags: []string{"xcuvk23", "cuvkwej23095489"}, + RepoTags: []string{"xcuvk2", "cuvkwej23095489"}, RepoDigests: []string{"1238", "4820940"}, Size_: 2048, Uid: &runtime.Int64Value{Value: int64(0)},