2013-03-27 23:58:22 +00:00
|
|
|
package omaha
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2013-04-01 16:53:53 +00:00
|
|
|
"fmt"
|
2013-03-27 23:58:22 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2013-04-01 16:53:53 +00:00
|
|
|
"testing"
|
2013-03-27 23:58:22 +00:00
|
|
|
)
|
|
|
|
|
2013-03-29 12:51:29 +00:00
|
|
|
func TestOmahaRequestUpdateCheck(t *testing.T) {
|
2013-06-24 03:32:43 +00:00
|
|
|
file, err := os.Open("../fixtures/update-engine/update/request.xml")
|
2013-03-27 23:58:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
fix, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
v := Request{}
|
|
|
|
xml.Unmarshal(fix, &v)
|
|
|
|
|
|
|
|
if v.Os.Version != "Indy" {
|
|
|
|
t.Error("Unexpected version", v.Os.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Apps[0].Id != "{87efface-864d-49a5-9bb3-4b050a7c227a}" {
|
|
|
|
t.Error("Expected an App Id")
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Apps[0].UpdateCheck == nil {
|
|
|
|
t.Error("Expected an UpdateCheck")
|
|
|
|
}
|
2013-03-29 12:51:29 +00:00
|
|
|
|
|
|
|
if v.Apps[0].Version != "ForcedUpdate" {
|
|
|
|
t.Error("Verison is ForcedUpdate")
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Apps[0].FromTrack != "developer-build" {
|
|
|
|
t.Error("developer-build")
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:08:19 +00:00
|
|
|
if v.Apps[0].Events[0].Type != "3" {
|
2013-03-29 12:51:29 +00:00
|
|
|
t.Error("developer-build")
|
|
|
|
}
|
2013-03-27 23:58:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 16:53:53 +00:00
|
|
|
func ExampleOmaha_NewResponse() {
|
|
|
|
response := NewResponse("unit-test")
|
|
|
|
app := response.AddApp("{52F1B9BC-D31A-4D86-9276-CBC256AADF9A}")
|
|
|
|
app.Status = "ok"
|
|
|
|
p := app.AddPing()
|
|
|
|
p.Status = "ok"
|
|
|
|
u := app.AddUpdateCheck()
|
|
|
|
u.Status = "ok"
|
2013-04-14 04:35:44 +00:00
|
|
|
u.AddUrl("http://localhost/updates")
|
|
|
|
m := u.AddManifest("9999.0.0")
|
2013-04-01 16:53:53 +00:00
|
|
|
m.AddPackage("+LXvjiaPkeYDLHoNKlf9qbJwvnk=", "update.gz", "67546213", true)
|
|
|
|
a := m.AddAction("postinstall")
|
|
|
|
a.ChromeOSVersion = "9999.0.0"
|
2013-04-11 19:08:55 +00:00
|
|
|
a.Sha256 = "0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg="
|
2013-04-01 16:53:53 +00:00
|
|
|
a.NeedsAdmin = false
|
|
|
|
a.IsDelta = true
|
2013-06-26 17:23:06 +00:00
|
|
|
a.DisablePayloadBackoff = true
|
2013-03-27 23:58:22 +00:00
|
|
|
|
2013-04-01 16:53:53 +00:00
|
|
|
if raw, err := xml.MarshalIndent(response, "", " "); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s%s\n", xml.Header, raw)
|
|
|
|
}
|
2013-03-27 23:58:22 +00:00
|
|
|
|
2013-04-01 16:53:53 +00:00
|
|
|
// Output:
|
|
|
|
// <?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
// <response protocol="3.0" server="unit-test">
|
|
|
|
// <daystart elapsed_seconds="0"></daystart>
|
|
|
|
// <app appid="{52F1B9BC-D31A-4D86-9276-CBC256AADF9A}" status="ok">
|
|
|
|
// <ping status="ok"></ping>
|
2013-04-14 04:35:44 +00:00
|
|
|
// <updatecheck status="ok">
|
|
|
|
// <urls>
|
|
|
|
// <url codebase="http://localhost/updates"></url>
|
|
|
|
// </urls>
|
|
|
|
// <manifest version="9999.0.0">
|
|
|
|
// <packages>
|
|
|
|
// <package hash="+LXvjiaPkeYDLHoNKlf9qbJwvnk=" name="update.gz" size="67546213" required="true"></package>
|
|
|
|
// </packages>
|
|
|
|
// <actions>
|
2013-06-26 17:23:06 +00:00
|
|
|
// <action event="postinstall" ChromeOSVersion="9999.0.0" sha256="0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg=" needsadmin="false" IsDelta="true" DisablePayloadBackoff="true"></action>
|
2013-04-14 04:35:44 +00:00
|
|
|
// </actions>
|
|
|
|
// </manifest>
|
|
|
|
// </updatecheck>
|
2013-04-01 16:53:53 +00:00
|
|
|
// </app>
|
|
|
|
// </response>
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleOmaha_NewRequest() {
|
|
|
|
request := NewRequest("Indy", "Chrome OS", "ForcedUpdate_x86_64", "")
|
|
|
|
app := request.AddApp("{27BD862E-8AE8-4886-A055-F7F1A6460627}", "1.0.0.0")
|
|
|
|
app.AddUpdateCheck()
|
2013-03-27 23:58:22 +00:00
|
|
|
|
2013-06-25 15:08:19 +00:00
|
|
|
event := app.AddEvent()
|
|
|
|
event.Type = "1"
|
|
|
|
event.Result = "0"
|
|
|
|
|
2013-03-27 23:58:22 +00:00
|
|
|
if raw, err := xml.MarshalIndent(request, "", " "); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s%s\n", xml.Header, raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output:
|
|
|
|
// <?xml version="1.0" encoding="UTF-8"?>
|
2013-04-01 16:53:53 +00:00
|
|
|
// <request protocol="3.0">
|
|
|
|
// <os platform="Chrome OS" version="Indy" sp="ForcedUpdate_x86_64"></os>
|
2013-03-27 23:58:22 +00:00
|
|
|
// <app appid="{27BD862E-8AE8-4886-A055-F7F1A6460627}" version="1.0.0.0">
|
|
|
|
// <updatecheck></updatecheck>
|
2013-06-25 15:08:19 +00:00
|
|
|
// <event eventtype="1" eventresult="0"></event>
|
2013-03-27 23:58:22 +00:00
|
|
|
// </app>
|
2013-04-01 16:53:53 +00:00
|
|
|
// </request>
|
2013-03-27 23:58:22 +00:00
|
|
|
}
|