Skip to content

Commit

Permalink
chore: minimal coding style changes
Browse files Browse the repository at this point in the history
No functional change.
  • Loading branch information
bassosimone committed Jun 27, 2024
1 parent a4e3646 commit da1e5b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions internal/oonirun/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions internal/oonirun/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit da1e5b4

Please sign in to comment.