Skip to content

Commit 93e64c8

Browse files
Add possibility to define a custom folder for temporary files. (#305)
1 parent 5085008 commit 93e64c8

File tree

12 files changed

+83
-31
lines changed

12 files changed

+83
-31
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: UnitTesting
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
GO111MODULE: off
7+
8+
jobs:
9+
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: src/github.com/newrelic/infra-integrations-sdk
16+
steps:
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v2
20+
21+
- name: Check out code into the Go module directory
22+
uses: actions/checkout@v2
23+
with:
24+
path: src/github.com/newrelic/infra-integrations-sdk
25+
26+
- name: Test
27+
env:
28+
GOPATH: "${{ github.workspace }}"
29+
run: env PATH="$PATH:$GOPATH/bin" make test

args/args.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type DefaultArgumentList struct {
2323
NriAddHostname bool `default:"false" help:"Add hostname attribute to the samples."`
2424
NriCluster string `default:"" help:"Optional. Cluster name"`
2525
NriService string `default:"" help:"Optional. Service name"`
26+
TempDir string `default:"" help:"Optional. Integrations path to store temporal data (defaults to os.tempDir if left empty)."`
2627
}
2728

2829
// All returns if all data should be published
@@ -81,12 +82,12 @@ func underscore(s string) string {
8182
// fields it defines. Each of the fields in the struct can define their defaults
8283
// and help string by using tags:
8384
//
84-
// type Arguments struct {
85-
// DefaultArgumentList
86-
// Argument1 bool `default:"false" help:"This is the help we will print"`
87-
// Argument2 int `default:"1" help:"This is the help we will print"`
88-
// Argument3 string `default:"value" help:"This is the help we will print"`
89-
// }
85+
// type Arguments struct {
86+
// DefaultArgumentList
87+
// Argument1 bool `default:"false" help:"This is the help we will print"`
88+
// Argument2 int `default:"1" help:"This is the help we will print"`
89+
// Argument3 string `default:"value" help:"This is the help we will print"`
90+
// }
9091
//
9192
// The fields in the struct will be populated with the values set either from
9293
// the command line or from environment variables.

data/metric/metrics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestSet_SetMetricsRatesAndDeltas(t *testing.T) {
130130
}
131131

132132
for _, tc := range testCases {
133-
t.Run(string(tc.sourceType), func(t *testing.T) {
133+
t.Run(tc.sourceType.String(), func(t *testing.T) {
134134

135135
persist.SetNow(growingTime)
136136

@@ -145,7 +145,7 @@ func TestSet_SetMetricsRatesAndDeltas(t *testing.T) {
145145

146146
func TestSet_SetMetricPositivesThrowsOnNegativeValues(t *testing.T) {
147147
for _, sourceType := range []SourceType{PDELTA, PRATE} {
148-
t.Run(string(sourceType), func(t *testing.T) {
148+
t.Run(sourceType.String(), func(t *testing.T) {
149149
persist.SetNow(growingTime)
150150
ms := NewSet(
151151
"some-event-type",

data/metric/source_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestSourceType_Positive(t *testing.T) {
2525
}
2626

2727
for _, tc := range testCases {
28-
t.Run(string(tc.sourceType), func(t *testing.T) {
28+
t.Run(tc.sourceType.String(), func(t *testing.T) {
2929
assert.Equal(t, tc.isPositive, tc.sourceType.IsPositive())
3030
})
3131
}

docs/toolset/args.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ consider. All of them are `bool` and default to `false`. They are described foll
3434
* `NriAddHostname`: if true, agent will decorate all the metrics with the `hostname`.
3535
* `NriCluster`: if any value is provided, all the metrics will be decorated with `clusterName: value`.
3636
* `NriService`: if any value is provided, all the metrics will be decorated with `serviceName: value`.
37+
* `TempDir`: Integrations path to store temporal data (it defaults to `os.TempDir()` if it's left empty).
3738

3839
An example of
3940

integration/integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func New(name, version string, opts ...Option) (i *Integration, err error) {
100100
}
101101

102102
if i.storer == nil {
103-
storePath, err := persist.NewStorePath(i.Name, i.CreateUniqueID(), i.logger, persist.DefaultTTL)
103+
storePath, err := persist.NewStorePath(i.Name, i.CreateUniqueID(), defaultArgs.TempDir, i.logger, persist.DefaultTTL)
104104
if err != nil {
105105
return nil, fmt.Errorf("can't create temporary directory for store: %s", err)
106106
}

integration/integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func TestIntegration_CreateUniqueID_Default(t *testing.T) {
464464
i, err := New("testIntegration", "0.0.0", Args(&al))
465465
assert.NoError(t, err)
466466

467-
assert.Equal(t, i.CreateUniqueID(), "3071eb6863e28435e6c7e0c2bbe55ecd")
467+
assert.Equal(t, i.CreateUniqueID(), "f2fbf79d935a14908cb886e98cff0879")
468468
}
469469

470470
func TestIntegration_CreateUniqueID_EnvironmentVar(t *testing.T) {
@@ -481,7 +481,7 @@ func TestIntegration_CreateUniqueID_EnvironmentVar(t *testing.T) {
481481
i, err := New("testIntegration", "0.0.0", Args(&al))
482482
assert.NoError(t, err)
483483

484-
assert.Equal(t, i.CreateUniqueID(), "2d998100982b7de9b4e446c85c3bed78")
484+
assert.Equal(t, i.CreateUniqueID(), "3d3c4d31fdec9ccd1250c9d080ca514f")
485485
}
486486

487487
type testWriter struct {

integration/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestItStoresOnDiskByDefault(t *testing.T) {
7272
assert.NoError(t, i.Publish())
7373

7474
// assert data has been flushed to disk
75-
storePath, err := persist.NewStorePath(i.Name, i.CreateUniqueID(), i.logger, persist.DefaultTTL)
75+
storePath, err := persist.NewStorePath(i.Name, i.CreateUniqueID(), "", i.logger, persist.DefaultTTL)
7676
assert.NoError(t, err)
7777

7878
c, err := persist.NewFileStore(storePath.GetFilePath(), log.NewStdErr(true), persist.DefaultTTL)

jmx/jmx_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ func TestQuery_WithSSL(t *testing.T) {
123123
}
124124

125125
func TestOpen_WithNrjmx(t *testing.T) {
126-
defer Close()
127-
128126
aux := os.Getenv("NR_JMX_TOOL")
129127
require.NoError(t, os.Unsetenv("NR_JMX_TOOL"))
130128

@@ -242,14 +240,14 @@ func Test_DefaultPath_IsCorrectForOs(t *testing.T) {
242240
}
243241

244242
func TestHostName(t *testing.T) {
245-
defer Close()
243+
cmd = nil
246244
host := "a-host"
247245
assert.NoError(t, OpenNoAuth(host, ""))
248246
assert.Equal(t, host, HostName())
249247
}
250248

251249
func TestPort(t *testing.T) {
252-
defer Close()
250+
cmd = nil
253251
port := "6666"
254252
assert.NoError(t, OpenNoAuth("", port))
255253
assert.Equal(t, port, Port())

persist/store_path.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type storePath struct {
2828
}
2929

3030
// NewStorePath create a new instance of StorePath
31-
func NewStorePath(integrationName, integrationID string, ilog log.Logger, ttl time.Duration) (StorePath, error) {
31+
func NewStorePath(integrationName, integrationID, customTempDir string, ilog log.Logger, ttl time.Duration) (StorePath, error) {
3232
if integrationName == "" {
3333
return nil, fmt.Errorf("integration name not specified")
3434
}
@@ -42,7 +42,7 @@ func NewStorePath(integrationName, integrationID string, ilog log.Logger, ttl ti
4242
}
4343

4444
return &storePath{
45-
dir: tmpIntegrationDir(),
45+
dir: tmpIntegrationDir(customTempDir),
4646
integrationName: integrationName,
4747
integrationID: integrationID,
4848
ilog: ilog,

0 commit comments

Comments
 (0)