Skip to content

Commit f613394

Browse files
authored
Remove definition type, add builder requirements param (#17)
1 parent dfeb706 commit f613394

File tree

5 files changed

+27
-76
lines changed

5 files changed

+27
-76
lines changed

client/build.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ import (
1616

1717
// Submit sends a build job to the Build Service. The context controls the
1818
// lifetime of the request.
19-
func (c *Client) Submit(ctx context.Context, d Definition, libraryRef string, libraryURL string) (bi BuildInfo, err error) {
20-
21-
b, err := json.Marshal(BuildRequest{
22-
Definition: d,
23-
LibraryRef: libraryRef,
24-
LibraryURL: libraryURL,
25-
})
19+
func (c *Client) Submit(ctx context.Context, br BuildRequest) (bi BuildInfo, err error) {
20+
b, err := json.Marshal(br)
2621
if err != nil {
2722
return
2823
}

client/build_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func TestSubmit(t *testing.T) {
5858
m.buildResponseCode = tt.responseCode
5959

6060
// Call the handler
61-
bi, err := c.Submit(tt.ctx, client.Definition{}, tt.libraryRef, "")
61+
bi, err := c.Submit(tt.ctx, client.BuildRequest{
62+
DefinitionRaw: []byte{},
63+
LibraryRef: tt.libraryRef,
64+
LibraryURL: "",
65+
})
6266

6367
if tt.expectSuccess {
6468
// Ensure the handler returned no error, and the response is as expected

client/client_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
imagePath = "/v1/image"
4848
)
4949

50-
func newResponse(m *mockService, id string, d client.Definition, libraryRef string) client.BuildInfo {
50+
func newResponse(m *mockService, id string, def []byte, libraryRef string) client.BuildInfo {
5151
libraryURL := url.URL{
5252
Scheme: "http",
5353
Host: m.httpAddr,
@@ -57,12 +57,12 @@ func newResponse(m *mockService, id string, d client.Definition, libraryRef stri
5757
}
5858

5959
return client.BuildInfo{
60-
ID: id,
61-
Definition: d,
62-
LibraryURL: libraryURL.String(),
63-
LibraryRef: libraryRef,
64-
IsComplete: true,
65-
ImageSize: 1,
60+
ID: id,
61+
DefinitionRaw: def,
62+
LibraryURL: libraryURL.String(),
63+
LibraryRef: libraryRef,
64+
IsComplete: true,
65+
ImageSize: 1,
6666
}
6767
}
6868

@@ -76,7 +76,7 @@ func (m *mockService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7676
}
7777
if m.buildResponseCode == http.StatusCreated {
7878
id := newObjectID()
79-
if err := jsonresp.WriteResponse(w, newResponse(m, id, br.Definition, br.LibraryRef), m.buildResponseCode); err != nil {
79+
if err := jsonresp.WriteResponse(w, newResponse(m, id, br.DefinitionRaw, br.LibraryRef), m.buildResponseCode); err != nil {
8080
m.t.Fatal(err)
8181
}
8282
} else {
@@ -91,7 +91,7 @@ func (m *mockService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9191
m.t.Fatalf("failed to parse ID '%v'", id)
9292
}
9393
if m.statusResponseCode == http.StatusOK {
94-
if err := jsonresp.WriteResponse(w, newResponse(m, id, client.Definition{}, ""), m.statusResponseCode); err != nil {
94+
if err := jsonresp.WriteResponse(w, newResponse(m, id, []byte{}, ""), m.statusResponseCode); err != nil {
9595
m.t.Fatal(err)
9696
}
9797
} else {
@@ -210,7 +210,11 @@ func TestBuild(t *testing.T) {
210210
m.imageResponseCode = tt.imageResponseCode
211211

212212
// Do it!
213-
bd, err := c.Submit(tt.ctx, client.Definition{}, tt.imagePath, url.String())
213+
bd, err := c.Submit(tt.ctx, client.BuildRequest{
214+
DefinitionRaw: []byte{},
215+
LibraryRef: tt.imagePath,
216+
LibraryURL: url.String(),
217+
})
214218
if !tt.expectSubmitSuccess {
215219
// Ensure the handler returned an error
216220
if err == nil {

client/definition.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

client/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111

1212
// BuildRequest contains the info necessary for submitting a build to build service
1313
type BuildRequest struct {
14-
Definition `json:"definition"`
15-
LibraryRef string `json:"libraryRef"`
16-
LibraryURL string `json:"libraryURL"`
17-
CallbackURL string `json:"callbackURL"`
14+
LibraryRef string `json:"libraryRef"`
15+
LibraryURL string `json:"libraryURL"`
16+
CallbackURL string `json:"callbackURL"`
17+
DefinitionRaw []byte `json:"definitionRaw"`
18+
BuilderRequirements map[string]string `json:"builderRequirements"`
1819
}
1920

2021
// BuildInfo contains the details of an individual build
@@ -26,8 +27,8 @@ type BuildInfo struct {
2627
CompleteTime *time.Time `json:"completeTime,omitempty"`
2728
ImageSize int64 `json:"imageSize,omitempty"`
2829
ImageChecksum string `json:"imageChecksum,omitempty"`
29-
Definition Definition `json:"definition"`
3030
LibraryRef string `json:"libraryRef"`
3131
LibraryURL string `json:"libraryURL"`
3232
CallbackURL string `json:"callbackURL"`
33+
DefinitionRaw []byte `json:"definitionRaw"`
3334
}

0 commit comments

Comments
 (0)