diff --git a/internal/oonirun/v2.go b/internal/oonirun/v2.go index 974be9790..625e44e4b 100644 --- a/internal/oonirun/v2.go +++ b/internal/oonirun/v2.go @@ -272,7 +272,7 @@ func v2MeasureHTTPS(ctx context.Context, config *LinkConfig, URL string) error { // pull a possibly new descriptor without updating the old descriptor clnt := config.Session.DefaultHTTPClient() - auth, err := maybeGetAuthenticationTokenFromFile(config.AuthFile) + auth, err := v2MaybeGetAuthenticationTokenFromFile(config.AuthFile) if err != nil { logger.Warnf("oonirun: failed to retrieve auth token: %v", err) } @@ -304,25 +304,25 @@ func v2MeasureHTTPS(ctx context.Context, config *LinkConfig, URL string) error { return V2MeasureDescriptor(ctx, config, newValue) } -func maybeGetAuthenticationTokenFromFile(path string) (string, error) { +func v2MaybeGetAuthenticationTokenFromFile(path string) (string, error) { if path != "" { - return readBearerTokenFromFile(path) + return v2ReadBearerTokenFromFile(path) } return "", nil } -// readBearerTokenFromFile tries to extract a valid (base64) bearer token from +// v2ReadBearerTokenFromFile tries to extract a valid (base64) bearer token from // the first line of the passed text file. // If there is an error while reading from the file, the error will be returned. // If we can read from the file but there's no valid token found, an empty string will be returned. -func readBearerTokenFromFile(filep string) (string, error) { - f, err := fsx.OpenFile(filep) +func v2ReadBearerTokenFromFile(fileName string) (string, error) { + filep, err := fsx.OpenFile(fileName) if err != nil { return "", err } - defer f.Close() + defer filep.Close() - scanner := bufio.NewScanner(f) + scanner := bufio.NewScanner(filep) // Scan the first line if scanner.Scan() { diff --git a/internal/oonirun/v2_test.go b/internal/oonirun/v2_test.go index 4cd58d014..d75761c4d 100644 --- a/internal/oonirun/v2_test.go +++ b/internal/oonirun/v2_test.go @@ -673,7 +673,7 @@ func Test_readFirstLineFromFile(t *testing.T) { defer f.Close() defer os.Remove(f.Name()) - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != "" { t.Fatal("expected empty string") } @@ -691,7 +691,7 @@ func Test_readFirstLineFromFile(t *testing.T) { defer f.Close() defer os.Remove(f.Name()) - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != "" { t.Fatal("expected empty string") } @@ -701,7 +701,7 @@ func Test_readFirstLineFromFile(t *testing.T) { }) t.Run("return error if file does not exist", func(t *testing.T) { - line, err := readBearerTokenFromFile(filepath.Join(t.TempDir(), "non-existent")) + line, err := v2ReadBearerTokenFromFile(filepath.Join(t.TempDir(), "non-existent")) if line != "" { t.Fatal("expected empty string") } @@ -721,7 +721,7 @@ func Test_readFirstLineFromFile(t *testing.T) { defer f.Close() defer os.Remove(f.Name()) - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != token { t.Fatalf("expected %s, got %s", token, line) } @@ -743,7 +743,7 @@ func Test_readFirstLineFromFile(t *testing.T) { defer f.Close() defer os.Remove(f.Name()) - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != token { t.Fatalf("expected %s, got %s", token, line) } @@ -765,7 +765,7 @@ func Test_readFirstLineFromFile(t *testing.T) { defer f.Close() defer os.Remove(f.Name()) - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != token { t.Fatalf("expected %s, got %s", token, line) } @@ -789,7 +789,7 @@ func Test_readFirstLineFromFile(t *testing.T) { expected := "" - line, err := readBearerTokenFromFile(f.Name()) + line, err := v2ReadBearerTokenFromFile(f.Name()) if line != expected { t.Fatalf("expected empty string, got %s", line) }