Skip to content

Commit

Permalink
Moves test to correct location and updates the help text of image cre…
Browse files Browse the repository at this point in the history
…ate and save

Signed-off-by: Caroline Scherf <[email protected]>
  • Loading branch information
fcaroline2020 committed Aug 2, 2023
1 parent 0c9899a commit 82f1e43
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 72 deletions.
2 changes: 1 addition & 1 deletion docs/kp_image_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for create
--local-path string path to local source code
--local-path-destination-image string registry location of local source image
--local-path-destination-image string registry location of where the local source code will be uploaded to
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
The output can be used with the "kubectl apply -f" command. To allow this, the command
Expand Down
2 changes: 1 addition & 1 deletion docs/kp_image_save.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for save
--local-path string path to local source code
--local-path string registry location of where the local source code will be uploaded to
--local-path-destination-image string registry location of source image
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/image/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
cmd.Flags().StringVar(&factory.GitRevision, "git-revision", "", "git revision such as commit, tag, or branch (default \"main\")")
cmd.Flags().StringVar(&factory.Blob, "blob", "", "source code blob url")
cmd.Flags().StringVar(&factory.LocalPath, "local-path", "", "path to local source code")
cmd.Flags().StringVar(&factory.LocalPathDestinationImage, "local-path-destination-image", "", "registry location of local source image")
cmd.Flags().StringVar(&factory.LocalPathDestinationImage, "local-path-destination-image", "", "registry location of where the local source code will be uploaded to")
cmd.Flags().StringVar(&subPath, "sub-path", "", "build code at the sub path located within the source code directory")
cmd.Flags().StringVarP(&factory.Builder, "builder", "b", "", "builder name")
cmd.Flags().StringVarP(&factory.ClusterBuilder, "cluster-builder", "c", "", "cluster builder name")
Expand Down
133 changes: 65 additions & 68 deletions pkg/commands/image/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,71 @@ Image Resource "some-image" created
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
it("sets the repository source path on the image", func() {
expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
APIVersion: "kpack.io/v1alpha2",
},
ObjectMeta: metav1.ObjectMeta{
Name: "some-image",
Namespace: defaultNamespace,
Annotations: map[string]string{},
},
Spec: v1alpha2.ImageSpec{
Tag: "some-registry.io/some-repo",
Builder: corev1.ObjectReference{
Kind: v1alpha2.ClusterBuilderKind,
Name: "default",
},
ServiceAccountName: "default",
Source: corev1alpha1.SourceConfig{
Registry: &corev1alpha1.Registry{
Image: "some-registry.io/some-repo-testing:source-id",
},
SubPath: "some-sub-path",
},
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Name: "some-key",
Value: "some-val",
},
},
Services: v1alpha2.Services{
{
APIVersion: "v1",
Kind: "SomeResource",
Name: "some-binding",
},
},
},
},
}
require.NoError(t, setLastAppliedAnnotation(expectedImage))

testhelpers.CommandTest{
Args: []string{
"some-image",
"--tag", "some-registry.io/some-repo",
"--local-path", "some-local-path",
"--local-path-destination-image", "some-registry.io/some-repo-testing",
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
},
ExpectedOutput: `Creating Image Resource...
Uploading to 'some-registry.io/some-repo-testing'...
Uploading 'some-registry.io/some-repo-testing:source-id'
Image Resource "some-image" created
`,
ExpectCreates: []runtime.Object{
expectedImage,
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
})
Expand Down Expand Up @@ -900,73 +965,5 @@ status: {}
})
})
})

when("local-source and local—path-destination-image is provided", func() {
it("sets the repository source path on the image", func() {
expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
APIVersion: "kpack.io/v1alpha2",
},
ObjectMeta: metav1.ObjectMeta{
Name: "some-image",
Namespace: defaultNamespace,
Annotations: map[string]string{},
},
Spec: v1alpha2.ImageSpec{
Tag: "some-registry.io/some-repo",
Builder: corev1.ObjectReference{
Kind: v1alpha2.ClusterBuilderKind,
Name: "default",
},
ServiceAccountName: "default",
Source: corev1alpha1.SourceConfig{
Registry: &corev1alpha1.Registry{
Image: "some-registry.io/some-repo-testing:source-id",
},
SubPath: "some-sub-path",
},
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Name: "some-key",
Value: "some-val",
},
},
Services: v1alpha2.Services{
{
APIVersion: "v1",
Kind: "SomeResource",
Name: "some-binding",
},
},
},
},
}
require.NoError(t, setLastAppliedAnnotation(expectedImage))

testhelpers.CommandTest{
Args: []string{
"some-image",
"--tag", "some-registry.io/some-repo",
"--local-path", "some-local-path",
"--local-path-destination-image", "some-registry.io/some-repo-testing",
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
},
ExpectedOutput: `Creating Image Resource...
Uploading to 'some-registry.io/some-repo-testing'...
Uploading 'some-registry.io/some-repo-testing:source-id'
Image Resource "some-image" created
`,
ExpectCreates: []runtime.Object{
expectedImage,
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
})
}
}
2 changes: 1 addition & 1 deletion pkg/commands/image/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
cmd.Flags().StringVar(&factory.GitRepo, "git", "", "git repository url")
cmd.Flags().StringVar(&factory.GitRevision, "git-revision", "", "git revision such as commit, tag, or branch (default \"main\")")
cmd.Flags().StringVar(&factory.Blob, "blob", "", "source code blob url")
cmd.Flags().StringVar(&factory.LocalPath, "local-path", "", "path to local source code")
cmd.Flags().StringVar(&factory.LocalPath, "local-path", "", "registry location of where the local source code will be uploaded to")
cmd.Flags().StringVar(&factory.LocalPathDestinationImage, "local-path-destination-image", "", "registry location of source image")
cmd.Flags().StringVar(&subPath, "sub-path", "", "build code at the sub path located within the source code directory")
cmd.Flags().StringVar(&factory.CacheSize, "cache-size", "", "cache size as a kubernetes quantity (default \"2G\")")
Expand Down

0 comments on commit 82f1e43

Please sign in to comment.