Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee8e48cd56 | |||
| 11866a3b29 | |||
| 08a411bccf | |||
| 91f954391e | |||
| d6efbd22fd | |||
| 3cf80ad127 | |||
| 17e9649d1e | |||
| 1fceb0e0da | |||
| b7bd30b550 |
23
CHANGELOG
23
CHANGELOG
@@ -1,5 +1,28 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
|
|
||||||
|
v1.17.1 - 2025-11-21
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
- certlib: various code cleanups.
|
||||||
|
|
||||||
|
v1.17.0 - 2025-11-21
|
||||||
|
|
||||||
|
Added:
|
||||||
|
- cmd/bcuz: unzips bandcamp archives.
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
- certlib: ergonomic improvements.
|
||||||
|
|
||||||
|
v1.16.3 - 2025-11-21
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
- msg: fixups and testing.
|
||||||
|
|
||||||
|
v1.16.2 - 2025-11-21
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
- msg: fill debug null pointer deref.
|
||||||
|
|
||||||
v1.16.1 - 2025-11-21
|
v1.16.1 - 2025-11-21
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
|
|||||||
@@ -448,13 +448,13 @@ func encodeCertsToFiles(
|
|||||||
derContent = append(derContent, cert.Raw...)
|
derContent = append(derContent, cert.Raw...)
|
||||||
}
|
}
|
||||||
files = append(files, fileEntry{
|
files = append(files, fileEntry{
|
||||||
name: baseName + ".crt",
|
name: baseName + ".cer",
|
||||||
content: derContent,
|
content: derContent,
|
||||||
})
|
})
|
||||||
} else if len(certs) > 0 {
|
} else if len(certs) > 0 {
|
||||||
// Individual DER file (should only have one cert)
|
// Individual DER file (should only have one cert)
|
||||||
files = append(files, fileEntry{
|
files = append(files, fileEntry{
|
||||||
name: baseName + ".crt",
|
name: baseName + ".cer",
|
||||||
content: certs[0].Raw,
|
content: certs[0].Raw,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -472,17 +472,17 @@ func encodeCertsToFiles(
|
|||||||
derContent = append(derContent, cert.Raw...)
|
derContent = append(derContent, cert.Raw...)
|
||||||
}
|
}
|
||||||
files = append(files, fileEntry{
|
files = append(files, fileEntry{
|
||||||
name: baseName + ".crt",
|
name: baseName + ".cer",
|
||||||
content: derContent,
|
content: derContent,
|
||||||
})
|
})
|
||||||
} else if len(certs) > 0 {
|
} else if len(certs) > 0 {
|
||||||
files = append(files, fileEntry{
|
files = append(files, fileEntry{
|
||||||
name: baseName + ".crt",
|
name: baseName + ".cer",
|
||||||
content: certs[0].Raw,
|
content: certs[0].Raw,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported encoding: %s (must be 'pem', 'der', or 'both')", encoding)
|
return nil, fmt.Errorf("unsupported encoding: %s (must be 'pem', 'der', 'both', 'crt', 'pemcrt')", encoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
return files, nil
|
return files, nil
|
||||||
|
|||||||
@@ -19,13 +19,21 @@ type KeySpec struct {
|
|||||||
Size int `yaml:"size"`
|
Size int `yaml:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ks KeySpec) String() string {
|
||||||
|
if strings.ToLower(ks.Algorithm) == nameEd25519 {
|
||||||
|
return nameEd25519
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s-%d", ks.Algorithm, ks.Size)
|
||||||
|
}
|
||||||
|
|
||||||
func (ks KeySpec) Generate() (crypto.PublicKey, crypto.PrivateKey, error) {
|
func (ks KeySpec) Generate() (crypto.PublicKey, crypto.PrivateKey, error) {
|
||||||
switch strings.ToLower(ks.Algorithm) {
|
switch strings.ToLower(ks.Algorithm) {
|
||||||
case "rsa":
|
case "rsa":
|
||||||
return GenerateKey(x509.RSA, ks.Size)
|
return GenerateKey(x509.RSA, ks.Size)
|
||||||
case "ecdsa":
|
case "ecdsa":
|
||||||
return GenerateKey(x509.ECDSA, ks.Size)
|
return GenerateKey(x509.ECDSA, ks.Size)
|
||||||
case "ed25519":
|
case nameEd25519:
|
||||||
return GenerateKey(x509.Ed25519, 0)
|
return GenerateKey(x509.Ed25519, 0)
|
||||||
default:
|
default:
|
||||||
return nil, nil, fmt.Errorf("unknown key algorithm: %s", ks.Algorithm)
|
return nil, nil, fmt.Errorf("unknown key algorithm: %s", ks.Algorithm)
|
||||||
@@ -38,7 +46,7 @@ func (ks KeySpec) SigningAlgorithm() (x509.SignatureAlgorithm, error) {
|
|||||||
return x509.SHA512WithRSAPSS, nil
|
return x509.SHA512WithRSAPSS, nil
|
||||||
case "ecdsa":
|
case "ecdsa":
|
||||||
return x509.ECDSAWithSHA512, nil
|
return x509.ECDSAWithSHA512, nil
|
||||||
case "ed25519":
|
case nameEd25519:
|
||||||
return x509.PureEd25519, nil
|
return x509.PureEd25519, nil
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("unknown key algorithm: %s", ks.Algorithm)
|
return 0, fmt.Errorf("unknown key algorithm: %s", ks.Algorithm)
|
||||||
@@ -52,7 +60,7 @@ type Subject struct {
|
|||||||
Province string `yaml:"province"`
|
Province string `yaml:"province"`
|
||||||
Organization string `yaml:"organization"`
|
Organization string `yaml:"organization"`
|
||||||
OrganizationalUnit string `yaml:"organizational_unit"`
|
OrganizationalUnit string `yaml:"organizational_unit"`
|
||||||
Email string `yaml:"email"`
|
Email []string `yaml:"email"`
|
||||||
DNSNames []string `yaml:"dns"`
|
DNSNames []string `yaml:"dns"`
|
||||||
IPAddresses []string `yaml:"ips"`
|
IPAddresses []string `yaml:"ips"`
|
||||||
}
|
}
|
||||||
@@ -84,6 +92,7 @@ func (cs CertificateRequest) Request(priv crypto.PrivateKey) (*x509.CertificateR
|
|||||||
PublicKeyAlgorithm: 0,
|
PublicKeyAlgorithm: 0,
|
||||||
PublicKey: getPublic(priv),
|
PublicKey: getPublic(priv),
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
|
EmailAddresses: cs.Subject.Email,
|
||||||
DNSNames: cs.Subject.DNSNames,
|
DNSNames: cs.Subject.DNSNames,
|
||||||
IPAddresses: ipAddresses,
|
IPAddresses: ipAddresses,
|
||||||
}
|
}
|
||||||
@@ -118,7 +127,7 @@ func (cs CertificateRequest) Generate() (crypto.PrivateKey, *x509.CertificateReq
|
|||||||
type Profile struct {
|
type Profile struct {
|
||||||
IsCA bool `yaml:"is_ca"`
|
IsCA bool `yaml:"is_ca"`
|
||||||
PathLen int `yaml:"path_len"`
|
PathLen int `yaml:"path_len"`
|
||||||
KeyUse string `yaml:"key_uses"`
|
KeyUse []string `yaml:"key_uses"`
|
||||||
ExtKeyUsages []string `yaml:"ext_key_usages"`
|
ExtKeyUsages []string `yaml:"ext_key_usages"`
|
||||||
Expiry string `yaml:"expiry"`
|
Expiry string `yaml:"expiry"`
|
||||||
}
|
}
|
||||||
@@ -149,15 +158,17 @@ func (p Profile) templateFromRequest(req *x509.CertificateRequest) (*x509.Certif
|
|||||||
IPAddresses: req.IPAddresses,
|
IPAddresses: req.IPAddresses,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok bool
|
for _, sku := range p.KeyUse {
|
||||||
certTemplate.KeyUsage, ok = keyUsageStrings[p.KeyUse]
|
ku, ok := keyUsageStrings[sku]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid key usage: %s", p.KeyUse)
|
return nil, fmt.Errorf("invalid key usage: %s", p.KeyUse)
|
||||||
|
}
|
||||||
|
|
||||||
|
certTemplate.KeyUsage |= ku
|
||||||
}
|
}
|
||||||
|
|
||||||
var eku x509.ExtKeyUsage
|
|
||||||
for _, extKeyUsage := range p.ExtKeyUsages {
|
for _, extKeyUsage := range p.ExtKeyUsages {
|
||||||
eku, ok = extKeyUsageStrings[extKeyUsage]
|
eku, ok := extKeyUsageStrings[extKeyUsage]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid extended key usage: %s", extKeyUsage)
|
return nil, fmt.Errorf("invalid extended key usage: %s", extKeyUsage)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ import (
|
|||||||
// oidEd25519 = asn1.ObjectIdentifier{1, 3, 101, 110}
|
// oidEd25519 = asn1.ObjectIdentifier{1, 3, 101, 110}
|
||||||
//)
|
//)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nameEd25519 = "ed25519"
|
||||||
|
)
|
||||||
|
|
||||||
func GenerateKey(algorithm x509.PublicKeyAlgorithm, bitSize int) (crypto.PublicKey, crypto.PrivateKey, error) {
|
func GenerateKey(algorithm x509.PublicKeyAlgorithm, bitSize int) (crypto.PublicKey, crypto.PrivateKey, error) {
|
||||||
var key crypto.PrivateKey
|
var key crypto.PrivateKey
|
||||||
var pub crypto.PublicKey
|
var pub crypto.PublicKey
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha1" // #nosec G505 this is the standard
|
"crypto/sha1" // #nosec G505 this is the standard
|
||||||
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"encoding/asn1"
|
"encoding/asn1"
|
||||||
@@ -15,7 +16,9 @@ import (
|
|||||||
|
|
||||||
"git.wntrmute.dev/kyle/goutils/certlib"
|
"git.wntrmute.dev/kyle/goutils/certlib"
|
||||||
"git.wntrmute.dev/kyle/goutils/die"
|
"git.wntrmute.dev/kyle/goutils/die"
|
||||||
|
"git.wntrmute.dev/kyle/goutils/fileutil"
|
||||||
"git.wntrmute.dev/kyle/goutils/lib"
|
"git.wntrmute.dev/kyle/goutils/lib"
|
||||||
|
"git.wntrmute.dev/kyle/goutils/lib/fetch"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -53,6 +56,30 @@ func (k *KeyInfo) SKI(displayMode lib.HexEncodeMode) (string, error) {
|
|||||||
return pubHashString, nil
|
return pubHashString, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Lookup(path string, tcfg *tls.Config) (*KeyInfo, error) {
|
||||||
|
if fileutil.FileDoesExist(path) {
|
||||||
|
return ParsePEM(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
server, err := fetch.ParseServer(path, tcfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, err := server.Get()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
material := &KeyInfo{
|
||||||
|
FileType: "certificate",
|
||||||
|
}
|
||||||
|
|
||||||
|
material.PublicKey, material.KeyType = parseCertificate(cert)
|
||||||
|
|
||||||
|
return material, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ParsePEM parses a PEM file and returns the public key and its type.
|
// ParsePEM parses a PEM file and returns the public key and its type.
|
||||||
func ParsePEM(path string) (*KeyInfo, error) {
|
func ParsePEM(path string) (*KeyInfo, error) {
|
||||||
material := &KeyInfo{}
|
material := &KeyInfo{}
|
||||||
@@ -79,7 +106,7 @@ func ParsePEM(path string) (*KeyInfo, error) {
|
|||||||
material.PublicKey, material.KeyType = parseKey(data)
|
material.PublicKey, material.KeyType = parseKey(data)
|
||||||
material.FileType = "private key"
|
material.FileType = "private key"
|
||||||
case "CERTIFICATE":
|
case "CERTIFICATE":
|
||||||
material.PublicKey, material.KeyType = parseCertificate(data)
|
material.PublicKey, material.KeyType = parseCertificateFile(data)
|
||||||
material.FileType = "certificate"
|
material.FileType = "certificate"
|
||||||
case "CERTIFICATE REQUEST":
|
case "CERTIFICATE REQUEST":
|
||||||
material.PublicKey, material.KeyType = parseCSR(data)
|
material.PublicKey, material.KeyType = parseCSR(data)
|
||||||
@@ -113,12 +140,17 @@ func parseKey(data []byte) ([]byte, string) {
|
|||||||
return public, kt
|
return public, kt
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCertificate(data []byte) ([]byte, string) {
|
func parseCertificateFile(data []byte) ([]byte, string) {
|
||||||
cert, err := x509.ParseCertificate(data)
|
cert, err := x509.ParseCertificate(data)
|
||||||
die.If(err)
|
die.If(err)
|
||||||
|
|
||||||
|
return parseCertificate(cert)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseCertificate(cert *x509.Certificate) ([]byte, string) {
|
||||||
pub := cert.PublicKey
|
pub := cert.PublicKey
|
||||||
var kt string
|
var kt string
|
||||||
|
|
||||||
switch pub.(type) {
|
switch pub.(type) {
|
||||||
case *rsa.PublicKey:
|
case *rsa.PublicKey:
|
||||||
kt = keyTypeRSA
|
kt = keyTypeRSA
|
||||||
|
|||||||
8
cmd/bcuz/README
Normal file
8
cmd/bcuz/README
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
bcuz: bandcamp unzip
|
||||||
|
|
||||||
|
When you download stuff from bandcamp, it gives you a zip file that
|
||||||
|
extracts files into the current directory. This is a quick hack tries
|
||||||
|
to parse the filename as "artist - album", unpack the contents to
|
||||||
|
"artist/album/*", and remove the zip file (which can be kept with
|
||||||
|
-k). Works on my machine™, good enough for me.
|
||||||
|
|
||||||
110
cmd/bcuz/main.go
Normal file
110
cmd/bcuz/main.go
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var unrestrictedDecompression bool
|
||||||
|
|
||||||
|
var keepArchive bool
|
||||||
|
|
||||||
|
func removedir(dir string, existed bool) {
|
||||||
|
if !existed {
|
||||||
|
os.RemoveAll(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unpackFile(path string) error {
|
||||||
|
var dir string
|
||||||
|
var existed bool
|
||||||
|
|
||||||
|
fmt.Printf("[+] processing %s:\n", path)
|
||||||
|
|
||||||
|
base := filepath.Base(path[:len(path)-4])
|
||||||
|
pieces := strings.SplitN(base, "-", 2)
|
||||||
|
if len(pieces) == 2 {
|
||||||
|
artist := strings.TrimSpace(pieces[0])
|
||||||
|
album := strings.TrimSpace(pieces[1])
|
||||||
|
dir = filepath.Join(artist, album)
|
||||||
|
} else {
|
||||||
|
dir = base
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := os.Stat(dir)
|
||||||
|
if err == nil {
|
||||||
|
existed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\tunpack directory: %s\n", dir)
|
||||||
|
err = os.MkdirAll(dir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := zip.OpenReader(path)
|
||||||
|
if err != nil {
|
||||||
|
removedir(dir, existed)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
|
var rc io.ReadCloser
|
||||||
|
for _, f := range r.File {
|
||||||
|
fmt.Printf("\tunpacking %s\n", f.FileHeader.Name)
|
||||||
|
rc, err = f.Open()
|
||||||
|
if err != nil {
|
||||||
|
rc.Close()
|
||||||
|
removedir(dir, existed)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.UncompressedSize64 > (f.CompressedSize64*32) && !unrestrictedDecompression {
|
||||||
|
rc.Close()
|
||||||
|
removedir(dir, existed)
|
||||||
|
return errors.New("file is too large to decompress (maybe a zip bomb)")
|
||||||
|
}
|
||||||
|
|
||||||
|
var out *os.File
|
||||||
|
out, err = os.Create(filepath.Join(dir, f.FileHeader.Name))
|
||||||
|
if err != nil {
|
||||||
|
rc.Close()
|
||||||
|
removedir(dir, existed)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(out, rc) // #nosec G110: handled with size check above
|
||||||
|
if err != nil {
|
||||||
|
rc.Close()
|
||||||
|
removedir(dir, existed)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Close()
|
||||||
|
rc.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !keepArchive {
|
||||||
|
return os.Remove(path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.BoolVar(&keepArchive, "k", false, "don't remove the archive file after unpacking")
|
||||||
|
flag.BoolVar(&unrestrictedDecompression, "u", false, "allow unrestricted decompression")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
for _, path := range flag.Args() {
|
||||||
|
err := unpackFile(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "[!] failed to process %s: %s\n", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,7 +111,7 @@ func buildExtraForPath(st unix.Stat_t, path string, setUID, setGID int) []byte {
|
|||||||
ctns = clampToInt32(ft.Changed.Nanosecond())
|
ctns = clampToInt32(ft.Changed.Nanosecond())
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildKGExtra(uid, gid, mode, cts, ctns)
|
return buildKGExtra(uid, gid, uint32(mode), cts, ctns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseKGExtra scans a gzip Extra blob and returns kgz metadata if present.
|
// parseKGExtra scans a gzip Extra blob and returns kgz metadata if present.
|
||||||
|
|||||||
16
msg/msg.go
16
msg/msg.go
@@ -13,6 +13,7 @@ package msg
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.wntrmute.dev/kyle/goutils/lib"
|
"git.wntrmute.dev/kyle/goutils/lib"
|
||||||
|
|
||||||
@@ -22,10 +23,19 @@ import (
|
|||||||
var (
|
var (
|
||||||
enableQuiet bool
|
enableQuiet bool
|
||||||
enableVerbose bool
|
enableVerbose bool
|
||||||
debug *dbg.DebugPrinter
|
|
||||||
w io.Writer
|
debug = dbg.New()
|
||||||
|
w io.Writer = os.Stdout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Reset() {
|
||||||
|
enableQuiet = false
|
||||||
|
enableVerbose = false
|
||||||
|
|
||||||
|
debug = dbg.New()
|
||||||
|
w = os.Stdout
|
||||||
|
}
|
||||||
|
|
||||||
func SetQuiet(q bool) {
|
func SetQuiet(q bool) {
|
||||||
enableQuiet = q
|
enableQuiet = q
|
||||||
}
|
}
|
||||||
@@ -123,5 +133,7 @@ func Println(a ...any) {
|
|||||||
// SetWriter changes the output for messages.
|
// SetWriter changes the output for messages.
|
||||||
func SetWriter(dst io.Writer) {
|
func SetWriter(dst io.Writer) {
|
||||||
w = dst
|
w = dst
|
||||||
|
dbgEnabled := debug.Enabled
|
||||||
debug = dbg.To(lib.WithCloser(w))
|
debug = dbg.To(lib.WithCloser(w))
|
||||||
|
debug.Enabled = dbgEnabled
|
||||||
}
|
}
|
||||||
|
|||||||
147
msg/msg_test.go
Normal file
147
msg/msg_test.go
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package msg_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.wntrmute.dev/kyle/goutils/msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkExpected(buf *bytes.Buffer, expected string) bool {
|
||||||
|
return buf.String() == expected
|
||||||
|
}
|
||||||
|
|
||||||
|
func resetBuf() *bytes.Buffer {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
msg.SetWriter(buf)
|
||||||
|
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerbosePrint(t *testing.T) {
|
||||||
|
buf := resetBuf()
|
||||||
|
|
||||||
|
msg.SetVerbose(false) // ensure verbose is explicitly not set
|
||||||
|
|
||||||
|
msg.Vprint("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Vprintf("hello, %s", "world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Vprintln("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.SetVerbose(true)
|
||||||
|
msg.Vprint("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Vprintf("hello, %s", "world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Vprintln("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world\n") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world\n", buf.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQuietPrint(t *testing.T) {
|
||||||
|
buf := resetBuf()
|
||||||
|
|
||||||
|
msg.SetQuiet(true)
|
||||||
|
|
||||||
|
msg.Qprint("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Qprintf("hello, %s", "world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Qprintln("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.SetQuiet(false)
|
||||||
|
msg.Qprint("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Qprintf("hello, %s", "world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Qprintln("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world\n") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world\n", buf.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDebugPrint(t *testing.T) {
|
||||||
|
buf := resetBuf()
|
||||||
|
|
||||||
|
msg.SetDebug(false) // ensure debug is explicitly not set
|
||||||
|
|
||||||
|
msg.Dprint("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Dprintf("hello, %s", "world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Dprintln("hello, world")
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.StackTrace()
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("expected no output, have %s", buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.SetDebug(true)
|
||||||
|
msg.Dprint("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Dprintf("hello, %s", "world")
|
||||||
|
if !checkExpected(buf, "hello, world") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.Dprintln("hello, world")
|
||||||
|
if !checkExpected(buf, "hello, world\n") {
|
||||||
|
t.Fatalf("expected output %q, have %q", "hello, world\n", buf.String())
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
msg.StackTrace()
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
t.Fatal("expected stack trace output, received no output")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user