Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #102 from google/uuid
Browse files Browse the repository at this point in the history
CUPS < 1.5 doesn't send printer-uuid attribute.
  • Loading branch information
vitalybuka committed Oct 4, 2015
2 parents 73a61d7 + d3fc912 commit 149c605
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cups/translate-attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func getUUID(printerTags map[string][]string) string {
uuid = u[0]
uuid = strings.TrimPrefix(uuid, "urn:")
uuid = strings.TrimPrefix(uuid, "uuid:")
} else if u, ok := printerTags[attrPrinterName]; ok {
// CUPS < 1.5 doesn't send a printer-uuid attribute.
uuid = u[0]
}
return uuid
}
Expand Down
20 changes: 20 additions & 0 deletions cups/translate-attrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ func TestGetUUID(t *testing.T) {
t.Logf("expected %s, got %s", expected, u)
t.Fail()
}

pt = map[string][]string{
attrPrinterUUID: []string{"urn:uuid:123"},
attrPrinterName: []string{"my-name"},
}
u = getUUID(pt)
if u != expected {
t.Logf("expected %s, got %s", expected, u)
t.Fail()
}

pt = map[string][]string{
attrPrinterName: []string{"my-name"},
}
expected = "my-name"
u = getUUID(pt)
if u != expected {
t.Logf("expected %s, got %s", expected, u)
t.Fail()
}
}

func TestGetState(t *testing.T) {
Expand Down

0 comments on commit 149c605

Please sign in to comment.