-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding context version of Check and Response.Apply methods.
- Loading branch information
Showing
4 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// +build go1.7 | ||
|
||
package equinox | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// CheckContext is like Check but includes a context. | ||
func CheckContext(ctx context.Context, appID string, opts Options) (Response, error) { | ||
var req, err = checkRequest(appID, &opts) | ||
|
||
if err != nil { | ||
return Response{}, err | ||
} | ||
|
||
req = req.WithContext(ctx) | ||
return doCheckRequest(opts, req) | ||
} | ||
|
||
// ApplyContext is like Apply but includes a context. | ||
func (r Response) ApplyContext(ctx context.Context) error { | ||
var req, opts, err = r.applyRequest() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
req = req.WithContext(ctx) | ||
|
||
return r.applyUpdate(req, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build go1.7 | ||
|
||
package equinox | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io/ioutil" | ||
"testing" | ||
"time" | ||
|
||
"github.com/equinox-io/equinox/proto" | ||
) | ||
|
||
func TestEndToEndContext(t *testing.T) { | ||
opts := setup(t, "TestEndtoEnd", proto.Response{ | ||
Available: true, | ||
Release: proto.Release{ | ||
Version: "0.1.2.3", | ||
Title: "Release Title", | ||
Description: "Release Description", | ||
CreateDate: time.Now(), | ||
}, | ||
Checksum: newSHA, | ||
Signature: signature, | ||
}) | ||
defer cleanup(opts) | ||
|
||
resp, err := CheckContext(context.Background(), fakeAppID, opts) | ||
if err != nil { | ||
t.Fatalf("Failed check: %v", err) | ||
} | ||
err = resp.ApplyContext(context.Background()) | ||
if err != nil { | ||
t.Fatalf("Failed apply: %v", err) | ||
} | ||
|
||
buf, err := ioutil.ReadFile(opts.TargetPath) | ||
if err != nil { | ||
t.Fatalf("Failed to read file: %v", err) | ||
} | ||
if !bytes.Equal(buf, newFakeBinary) { | ||
t.Fatalf("Binary did not update to new expected value. Got %v, expected %v", buf, newFakeBinary) | ||
} | ||
} |