forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a common package for specifying useragent and adopt that everywhere
There were 5 different formats for the Packer useragent string. This fixes that and unifies it into a helper package. I did not touch oracle's user-agent, because it looked kinda special.
- Loading branch information
Showing
7 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package useragent | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/hashicorp/packer/version" | ||
) | ||
|
||
var ( | ||
// projectURL is the project URL. | ||
projectURL = "https://www.packer.io/" | ||
|
||
// rt is the runtime - variable for tests. | ||
rt = runtime.Version() | ||
|
||
// versionFunc is the func that returns the current version. This is a | ||
// function to take into account the different build processes and distinguish | ||
// between enterprise and oss builds. | ||
versionFunc = func() string { | ||
return version.FormattedVersion() | ||
} | ||
) | ||
|
||
// String returns the consistent user-agent string for Packer. | ||
func String() string { | ||
return fmt.Sprintf("Packer/%s (+%s; %s)", | ||
versionFunc(), projectURL, rt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package useragent | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestUserAgent(t *testing.T) { | ||
projectURL = "https://packer-test.com" | ||
rt = "go5.0" | ||
versionFunc = func() string { return "1.2.3" } | ||
|
||
act := String() | ||
|
||
exp := "Packer/1.2.3 (+https://packer-test.com; go5.0)" | ||
if exp != act { | ||
t.Errorf("expected %q to be %q", act, exp) | ||
} | ||
} |