261101.4 · 5735ff673a95384397d923bbcec92a411a6328d1
main.go splits by purpose
main.go held argument parsing, endpoint and token resolution and opening a browser, beside the program's start. They move to args.go, endpoint.go and browser.go, and main_test.go's tests go with the code they cover. main.go keeps main, the reporter, detaching and error codes.
Declarations moved unchanged, as a sorted comparison of every line outside the import blocks confirms. git blame -C -C traces them.
reading declarations
Changes to endpoint_test.go. All files
@@ -0,0 +1,39 @@+package main++import (+ "strings"+ "testing"+)++// CAP_NET_BIND_SERVICE is bit 10 of the effective set.+func TestHasCap(t *testing.T) {+ for status, want := range map[string]bool{+ "Name:\t" + progName + "\nCapInh:\t0000000000000000\nCapEff:\t0000000000000400\n": true,+ "CapEff:\t000001ffffffffff\n": true,+ "CapPrm:\t0000000000000400\nCapEff:\t0000000000000000\n": false,+ "Name:\t" + progName + "\n": false,+ } {+ if got := hasCap(status, capNetBindService); got != want {+ t.Errorf("%q: %v, want %v", status, got, want)+ }+ }+}++// A chosen token comes from WWW_SECRET, never the command line, and a bad+// one's error names the variable without echoing the secret.+func TestSecretToken(t *testing.T) {+ t.Setenv(secretEnv, "k3x9")+ if got, err := secretToken(); err != nil || got != "k3x9" {+ t.Errorf("set: %q, %v; want k3x9", got, err)+ }+ t.Setenv(secretEnv, "a/b")+ if _, err := secretToken(); err == nil || !strings.Contains(err.Error(), secretEnv) || strings.Contains(err.Error(), "a/b") {+ t.Errorf("bad token: %v; want an error naming %s without the token", err, secretEnv)+ }+ t.Setenv(secretEnv, "")+ a, errA := secretToken()+ b, errB := secretToken()+ if errA != nil || errB != nil || a == "" || a == b {+ t.Errorf("unset: %q, %q, %v, %v; want two different random tokens", a, b, errA, errB)+ }+}