Skip to content

Commit

Permalink
test: add job container image tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurcgc committed Oct 31, 2023
1 parent 6568109 commit 070afa0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/build/buildkit/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,30 @@ func TestBuildKit_Build_FromContainerImages(t *testing.T) {
},
}, appFiles)
})

t.Run("container image without Tsuru app files (tsuru.yaml, Procfile) + job image push", func(t *testing.T) {
req := &pb.BuildRequest{
Kind: pb.BuildKind_BUILD_KIND_JOB_CREATE_WITH_CONTAINER_IMAGE,
Job: &pb.TsuruJob{
Name: "my-job",
},
SourceImage: "nginx:1.22-alpine",
DestinationImages: []string{baseRegistry(t, "job-my-job", "")},
PushOptions: &pb.PushOptions{InsecureRegistry: registryHTTP},
}

appFiles, err := NewBuildKit(bc, BuildKitOptions{TempDir: t.TempDir()}).
Build(context.TODO(), req, os.Stdout)

require.NoError(t, err)
assert.Equal(t, &pb.TsuruConfig{
ImageConfig: &pb.ContainerImageConfig{
Entrypoint: []string{"/docker-entrypoint.sh"},
Cmd: []string{"nginx", "-g", "daemon off;"},
ExposedPorts: []string{"80/tcp"},
},
}, appFiles)
})
}

func TestBuildKit_Build_FromContainerFile(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/build/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ func TestBuild(t *testing.T) {
},
},

"missing job, when kind is from job": {
req: &pb.BuildRequest{
SourceImage: "tsuru/scratch:latest",
DestinationImages: []string{"registry.example.com/tsuru/app-my-app:v1"},
Kind: pb.BuildKind_BUILD_KIND_JOB_CREATE_WITH_CONTAINER_IMAGE,
},
assert: func(t *testing.T, stream pb.Build_BuildClient, err error) {
require.NoError(t, err)
require.NotNil(t, stream)
_, _, err = readResponse(t, stream)
assert.EqualError(t, err, status.Error(codes.InvalidArgument, "job cannot be nil").Error())
},
},

"deploy from source code, empty source image": {
req: &pb.BuildRequest{
DestinationImages: []string{"registry.example.com/tsuru/app-my-app:v1"},
Expand Down

0 comments on commit 070afa0

Please sign in to comment.