Skip to content

Commit

Permalink
maint(go): Upgrade to Go 1.22.0 (#921)
Browse files Browse the repository at this point in the history
Upgrade module and package to Go 1.22.0
Remove loop closure variable redeclaration

Note: once the end to end work is done to run on PR, we need to ensure
we include either a ppa with go 1.22.0 or get it backported already to
the targetted distro.
  • Loading branch information
didrocks authored Feb 22, 2024
2 parents e09b0b3 + 0f3b938 commit 62e0524
Show file tree
Hide file tree
Showing 60 changed files with 14 additions and 160 deletions.
2 changes: 0 additions & 2 deletions cmd/adsysd/integration_tests/adsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ socket: %s`, socket)), 0600)
"version": {args: []string{"version"}},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
_, err = runClient(t, confFile, tc.args...)
require.Error(t, err, "command should fail")
Expand Down Expand Up @@ -155,7 +154,6 @@ func TestCommandsTimeouts(t *testing.T) {
"0 is no timeout": {timeout: 0},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
// We only implement one command to test the client timeout functionality
timeoutServer := timeoutOnVersionServer{callbackHandled: make(chan struct{})}
Expand Down
2 changes: 0 additions & 2 deletions cmd/adsysd/integration_tests/adsysctl_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestDocChapter(t *testing.T) {
"Error on nonexistent chapter": {chapter: "nonexistent-chapter", wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.systemAnswer == "" {
tc.systemAnswer = "polkit_yes"
Expand Down Expand Up @@ -91,7 +90,6 @@ func TestDocCompletion(t *testing.T) {
"Empty completion content on daemon not responding": {daemonNotStarted: true, wantCompletionEmpty: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.systemAnswer == "" {
tc.systemAnswer = "polkit_yes"
Expand Down
5 changes: 0 additions & 5 deletions cmd/adsysd/integration_tests/adsysctl_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestPolicyAdmx(t *testing.T) {
"Error on daemon not responding": {arg: "lts-only", daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.systemAnswer)

Expand Down Expand Up @@ -120,7 +119,6 @@ func TestPolicyApplied(t *testing.T) {
"Error on daemon not responding": {daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.systemAnswer == "" {
tc.systemAnswer = "polkit_yes"
Expand Down Expand Up @@ -994,7 +992,6 @@ func TestPolicyUpdate(t *testing.T) {
},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.systemAnswer == "" {
tc.systemAnswer = "polkit_yes"
Expand Down Expand Up @@ -1215,7 +1212,6 @@ func TestPolicyDebugScriptDump(t *testing.T) {
"Error on daemon not responding for cert-autoenroll": {script: "cert-autoenroll", cmdName: "cert-autoenroll-script", path: "internal/policies/certificate", daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.systemAnswer)

Expand Down Expand Up @@ -1271,7 +1267,6 @@ func TestPolicyDebugTicketPath(t *testing.T) {
"Error if ticket path is a directory": {pathIsDir: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
// Empty username means current user
if tc.username == "" {
Expand Down
3 changes: 0 additions & 3 deletions cmd/adsysd/integration_tests/adsysctl_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestServiceStop(t *testing.T) {
"Error on daemon not responding": {daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.daemonAnswer)

Expand Down Expand Up @@ -167,7 +166,6 @@ func TestServiceCat(t *testing.T) {
"Error on daemon not responding - cover client": {daemonNotStarted: true, coverCatClient: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.systemAnswer)

Expand Down Expand Up @@ -299,7 +297,6 @@ func TestServiceStatus(t *testing.T) {
"Error on daemon not responding": {daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.systemAnswer)

Expand Down
1 change: 0 additions & 1 deletion cmd/adsysd/integration_tests/adsysctl_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestVersion(t *testing.T) {
"Error on daemon not responding": {daemonNotStarted: true, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
dbusAnswer(t, tc.systemAnswer)

Expand Down
1 change: 0 additions & 1 deletion cmd/adsysd/integration_tests/adsysd_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestAdsysdMount(t *testing.T) {
"Errors out and prints usage message when executed with more than 2 arguments": {addArgs: []string{"more", "than", "two"}, wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.sessionAnswer == "" {
tc.sessionAnswer = "polkit_yes"
Expand Down
2 changes: 0 additions & 2 deletions cmd/adsysd/integration_tests/adsysd_scripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestAdsysdRunScripts(t *testing.T) {
}

for name, tc := range tests {
tc := tc
name := name
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion cmd/adsysd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestRun(t *testing.T) {
"Send SIGHUP with exit": {sendSig: syscall.SIGHUP, hupReturn: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
// Signal handlers tests: can’t be parallel

Expand Down
4 changes: 0 additions & 4 deletions cmd/adwatchd/integration_tests/adwatchd_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func TestServiceStateChange(t *testing.T) {
"uninstall and restart": {sequence: []string{"uninstall", "stop"}, wantErrAt: []int{1}},
}
for name, tc := range tests {
tc := tc
name := name
t.Run(name, func(t *testing.T) {
var err error

Expand Down Expand Up @@ -240,8 +238,6 @@ func TestServiceConfigFlagUsage(t *testing.T) {
"install": {wantConfig: true},
}
for name, tc := range tests {
tc := tc
name := name
t.Run(name, func(t *testing.T) {
r, w, err := os.Pipe()
require.NoError(t, err, "Setup: pipe shouldn't fail")
Expand Down
5 changes: 2 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Maintainer: Ubuntu Developers <[email protected]>
Build-Depends: debhelper-compat (= 13),
dh-apport,
dh-golang,
golang-go (>= 2:1.21~),
golang-go (>= 2:1.22~),
apparmor,
dbus,
libdbus-1-dev,
Expand All @@ -20,14 +20,13 @@ Build-Depends: debhelper-compat (= 13),
samba-dsdb-modules,
Standards-Version: 4.5.1
XS-Go-Import-Path: github.com/ubuntu/adsys
Homepage: https://github.com/ubuntu/adsys
Homepage: <https://github.com/ubuntu/adsys>
Description: AD SYStem integration
ADSys is an AD SYStem tool to integrate GPOs with a linux system.
It allows one to handle machine and users GPOs, mapping them to dconf keys,
apparmor rules, mounts, proxy settings, certificate autoenrollment and running
scripts at different points in time.


Package: adsys
Architecture: any
Built-Using: ${misc:Built-Using},
Expand Down
2 changes: 0 additions & 2 deletions e2e/internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestInventory(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.fromState == "" {
tc.fromState = inventory.Null
Expand Down Expand Up @@ -110,7 +109,6 @@ func TestExecute(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.action == nil {
tc.action = mockAction
Expand Down
8 changes: 4 additions & 4 deletions e2e/scripts/patches/focal.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ index ccf213e0..40a2aa9f 100644
+Build-Depends: debhelper-compat (= 12),
dh-apport,
dh-golang,
- golang-go (>= 2:1.21~),
+ golang-1.21-go,
- golang-go (>= 2:1.22~),
+ golang-1.22-go,
apparmor,
dbus,
libdbus-1-dev,
Expand All @@ -23,8 +23,8 @@ index 43646c6a..0708aa3d 100755
# Tests needing sudo will be skipped automatically
export ADSYS_SKIP_INTEGRATION_TESTS=1

+# Run with Go 1.21
+export PATH := /usr/lib/go-1.21/bin/:$(PATH)
+# Run with Go 1.22
+export PATH := /usr/lib/go-1.22/bin/:$(PATH)
+
%:
dh $@ --buildsystem=golang --with=golang,apport
Expand Down
8 changes: 4 additions & 4 deletions e2e/scripts/patches/jammy.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ index ccf213e0..2d34a328 100644
Build-Depends: debhelper-compat (= 13),
dh-apport,
dh-golang,
- golang-go (>= 2:1.21~),
+ golang-1.21-go,
- golang-go (>= 2:1.22~),
+ golang-1.22-go,
apparmor,
dbus,
libdbus-1-dev,
Expand All @@ -19,8 +19,8 @@ index 43646c6a..403e7bb9 100755
# Tests needing sudo will be skipped automatically
export ADSYS_SKIP_INTEGRATION_TESTS=1

+# Run with Go 1.21
+export PATH := /usr/lib/go-1.21/bin/:$(PATH)
+# Run with Go 1.22
+export PATH := /usr/lib/go-1.22/bin/:$(PATH)
+
%:
dh $@ --buildsystem=golang --with=golang,apport
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/ubuntu/adsys

go 1.21.0

toolchain go1.21.6
go 1.22.0

require (
github.com/charmbracelet/bubbles v0.18.0
Expand Down
8 changes: 0 additions & 8 deletions internal/ad/ad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestNew(t *testing.T) {
"error on backend ServerFQDN random failure": {backendServerFQDNError: errors.New("Some failure on ServerFQDN"), wantErr: true},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
runDir, cacheDir := t.TempDir(), t.TempDir()
Expand Down Expand Up @@ -540,7 +539,6 @@ func TestGetPolicies(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel() // libsmbclient overrides SIGCHILD, but we have one global lock

Expand Down Expand Up @@ -692,7 +690,6 @@ func TestGetPoliciesOffline(t *testing.T) {
},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -833,7 +830,6 @@ func TestGetPoliciesWorkflows(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel() // libsmbclient overrides SIGCHILD, but we have one global lock

Expand Down Expand Up @@ -996,7 +992,6 @@ func TestGetPoliciesConcurrently(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel() // libsmbclient overrides SIGCHILD, but we have one global lock

Expand Down Expand Up @@ -1155,7 +1150,6 @@ func TestListUsers(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1228,7 +1222,6 @@ func TestGetInfo(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1284,7 +1277,6 @@ func TestNormalizeTargetName(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
9 changes: 0 additions & 9 deletions internal/ad/admxgen/admxgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func TestExpand(t *testing.T) {
"dconf generation fails": {root: "unsupported dconf type", wantErr: true},
}
for name, tc := range tests {
name := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -102,9 +99,6 @@ func TestGenerateAD(t *testing.T) {
"admx generation fails": {destIsFile: true, wantErr: true},
}
for name, tc := range tests {
name := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -161,9 +155,6 @@ func TestGenerateDoc(t *testing.T) {
"doc generation fails": {destIsFile: true, wantErr: true},
}
for name, tc := range tests {
name := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/ad/admxgen/dconf/dconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestGenerate(t *testing.T) {
}
for name, tc := range tests {
def := strings.ToLower(strings.ReplaceAll(name, " ", "_"))
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/ad/admxgen/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func Expand(src, dst, root, currentSession string) error {
expandedPoliciesStream := make(chan []common.ExpandedPolicy, len(files))
var g errgroup.Group
for _, f := range files {
f := f
g.Go(func() error {
t := strings.TrimSuffix(strings.ToLower(filepath.Base(f)), ".yaml")
if t == "categories" {
Expand Down
9 changes: 0 additions & 9 deletions internal/ad/admxgen/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ func TestGenerateExpandedCategories(t *testing.T) {
"category definition doesn't exist": {wantErrLoadDefinitions: true},
}
for name, tc := range tests {
name := name
categoryDefinition := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -167,9 +164,6 @@ func TestExpandedCategoriesToADMX(t *testing.T) {
"error on destination creation": {destIsFile: true, wantErr: true},
}
for name, tc := range tests {
name := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
dst := t.TempDir()
Expand Down Expand Up @@ -267,9 +261,6 @@ func TestExpandedCategoriesToMD(t *testing.T) {
"error on destination creation": {destIsFile: true, wantErr: true},
}
for name, tc := range tests {
name := name

tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
dst := filepath.Join(t.TempDir(), "subdir")
Expand Down
1 change: 0 additions & 1 deletion internal/ad/adsys-gpolist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func TestAdsysGPOList(t *testing.T) {
},
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
if tc.objectClass == "" {
tc.objectClass = "user"
Expand Down
1 change: 0 additions & 1 deletion internal/ad/backends/sss/sss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func TestSSSD(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit 62e0524

Please sign in to comment.