forked from raystack/frontier
-
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.
feat: add stdout repository activity (#40)
- Loading branch information
Showing
13 changed files
with
143 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package activity | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/goto/salt/audit" | ||
) | ||
|
||
type StdoutRepository struct { | ||
writer io.Writer | ||
} | ||
|
||
func NewStdoutRepository(writer io.Writer) *StdoutRepository { | ||
return &StdoutRepository{ | ||
writer: writer, | ||
} | ||
} | ||
|
||
func (r StdoutRepository) Insert(ctx context.Context, log *audit.Log) error { | ||
return json.NewEncoder(r.writer).Encode(log) | ||
} |
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,63 @@ | ||
package body_extractor | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestJSONPayloadHandler_Extract(t *testing.T) { | ||
defaultTestMessage := map[string]any{ | ||
"k1": "v1", | ||
"nested_k1": map[string]any{ | ||
"k1_1": "v1", | ||
"k2_2": 1, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
key string | ||
testMessage any | ||
want any | ||
wantErrString string | ||
}{ | ||
{ | ||
name: "should return error if field not exist", | ||
key: "x", | ||
testMessage: defaultTestMessage, | ||
wantErrString: "failed to find field: x", | ||
}, | ||
{ | ||
name: "should return value if field found", | ||
key: "nested_k1.k2_2", | ||
testMessage: defaultTestMessage, | ||
want: float64(1), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
h := JSONPayloadHandler{} | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt := tt | ||
t.Parallel() | ||
|
||
msg, err := json.Marshal(tt.testMessage) | ||
assert.NoError(t, err) | ||
|
||
testReader := io.NopCloser(bytes.NewBuffer(msg)) | ||
extractedData, err := h.Extract(&testReader, tt.key) | ||
|
||
if tt.wantErrString != "" { | ||
assert.Equal(t, tt.wantErrString, err.Error()) | ||
} else { | ||
if diff := cmp.Diff(tt.want, extractedData); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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