Repository: syncthing/syncthing
File: lib/api/api_test.go (Go)

Code before:
				t.Parallel()
				resp := httpGetAuthorizationBearer(url, testAPIKey)
				if resp.StatusCode != expectedOkStatus {
					t.Errorf("Unexpected non-%d return code %d for Authorization: Bearer", expectedOkStatus, resp.StatusCode)
				}
				if hasSessionCookie(resp.Cookies()) {
					t.Errorf("Unexpected session cookie for bad Authorization: Bearer")
				}
			})
		})
	}

	testWith(true, http.StatusOK, http.StatusOK, "/")
	testWith(true, http.StatusOK, http.StatusUnauthorized, "/meta.js")
	testWith(true, http.StatusNotFound, http.StatusUnauthorized, "/any-path/that/does/nooooooot/match-any/noauth-pattern")

	testWith(false, http.StatusOK, http.StatusOK, "/")
	testWith(false, http.StatusOK, http.StatusForbidden, "/meta.js")
	testWith(false, http.StatusNotFound, http.StatusForbidden, "/any-path/that/does/nooooooot/match-any/noauth-pattern")

	t.Run("Password change invalidates old and enables new password", func(t *testing.T) {
		t.Parallel()

		// This test needs a longer-than-default shutdown timeout to finish saving
		// config changes when running on GitHub Actions
		shutdownTimeout := testutil.IfExpr(os.Getenv("CI") == "true", 1000*time.Millisecond, 0)

		initConfig := func(password string, t *testing.T) config.Wrapper {
			gui := config.GUIConfiguration{
				RawAddress: "127.0.0.1:0",
				APIKey:     testAPIKey,
				User:       "user",
			}
			if err := gui.SetPassword(password); err != nil {
				t.Fatal(err, "Failed to set initial password")
			}
			cfg := config.Configuration{
				GUI: gui,
			}

			tmpFile, err := os.CreateTemp("", "syncthing-testConfig-Password-*")
			if err != nil {
				t.Fatal(err, "Failed to create tmpfile for test")
			}
			w := config.Wrap(tmpFile.Name(), cfg, protocol.LocalDeviceID, events.NoopLogger)
			tmpFile.Close()
			cfgCtx, cfgCancel := context.WithCancel(context.Background())
			go w.Serve(cfgCtx)
			t.Cleanup(func() {
				os.Remove(tmpFile.Name())
				cfgCancel()

Review comment (suggestion):
I realise you probably come from a language with `?:` but in Go this is typically

```
var shutdownTimeout time.Duration
if os.Getenv("CI") != "" {
  shutdownTimeout = time.Second
}
```

Code after:
				resp := httpGetAuthorizationBearer(url, testAPIKey)
				if resp.StatusCode != expectedOkStatus {
					t.Errorf("Unexpected non-%d return code %d for Authorization: Bearer", expectedOkStatus, resp.StatusCode)
				}
				if hasSessionCookie(resp.Cookies()) {
					t.Errorf("Unexpected session cookie for bad Authorization: Bearer")
				}
			})
		})
	}

	testWith(true, http.StatusOK, http.StatusOK, "/")
	testWith(true, http.StatusOK, http.StatusUnauthorized, "/meta.js")
	testWith(true, http.StatusNotFound, http.StatusUnauthorized, "/any-path/that/does/nooooooot/match-any/noauth-pattern")

	testWith(false, http.StatusOK, http.StatusOK, "/")
	testWith(false, http.StatusOK, http.StatusForbidden, "/meta.js")
	testWith(false, http.StatusNotFound, http.StatusForbidden, "/any-path/that/does/nooooooot/match-any/noauth-pattern")

	t.Run("Password change invalidates old and enables new password", func(t *testing.T) {
		t.Parallel()

		// This test needs a longer-than-default shutdown timeout to finish saving
		// config changes when running on GitHub Actions
		shutdownTimeout := time.Second

		initConfig := func(password string, t *testing.T) config.Wrapper {
			gui := config.GUIConfiguration{
				RawAddress: "127.0.0.1:0",
				APIKey:     testAPIKey,
				User:       "user",
			}
			if err := gui.SetPassword(password); err != nil {
				t.Fatal(err, "Failed to set initial password")
			}
			cfg := config.Configuration{
				GUI: gui,
			}

			tmpFile, err := os.CreateTemp("", "syncthing-testConfig-Password-*")
			if err != nil {
				t.Fatal(err, "Failed to create tmpfile for test")
			}
			w := config.Wrap(tmpFile.Name(), cfg, protocol.LocalDeviceID, events.NoopLogger)
			tmpFile.Close()
			cfgCtx, cfgCancel := context.WithCancel(context.Background())
			go w.Serve(cfgCtx)
			t.Cleanup(func() {
				os.Remove(tmpFile.Name())
				cfgCancel()
			})