-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright © by Jeff Foley 2017-2024. All rights reserved. | ||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package property | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
|
||
model "github.com/owasp-amass/open-asset-model" | ||
) | ||
|
||
// SourceProperty represents a source of data in the graph. | ||
type SourceProperty struct { | ||
Source string `json:"name"` | ||
Confidence int `json:"confidence"` | ||
} | ||
|
||
// Name implements the Property interface. | ||
func (p SourceProperty) Name() string { | ||
return p.Source | ||
} | ||
|
||
// Value implements the Property interface. | ||
func (p SourceProperty) Value() string { | ||
return strconv.Itoa(p.Confidence) | ||
} | ||
|
||
// PropertyType implements the Property interface. | ||
func (p SourceProperty) PropertyType() model.PropertyType { | ||
return model.SourceProperty | ||
} | ||
|
||
// JSON implements the Property interface. | ||
func (p SourceProperty) JSON() ([]byte, error) { | ||
return json.Marshal(p) | ||
} |
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,66 @@ | ||
// Copyright © by Jeff Foley 2017-2024. All rights reserved. | ||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package property | ||
|
||
import ( | ||
"testing" | ||
|
||
model "github.com/owasp-amass/open-asset-model" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSourcePropertyName(t *testing.T) { | ||
want := "anything" | ||
sp := SourceProperty{ | ||
Source: "anything", | ||
Confidence: 80, | ||
} | ||
|
||
if got := sp.Name(); got != want { | ||
t.Errorf("SourceProperty.Name() = %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestSourcePropertyValue(t *testing.T) { | ||
want := "80" | ||
sp := SourceProperty{ | ||
Source: "anything", | ||
Confidence: 80, | ||
} | ||
|
||
if got := sp.Value(); got != want { | ||
t.Errorf("SourceProperty.Value() = %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestSourcePropertyImplementsProperty(t *testing.T) { | ||
var _ model.Property = SourceProperty{} // Verify proper implementation of the Property interface | ||
var _ model.Property = (*SourceProperty)(nil) // Verify *SourceProperty properly implements the Property interface. | ||
} | ||
|
||
func TestSourceProperty(t *testing.T) { | ||
t.Run("Test successful creation of SourceProperty", func(t *testing.T) { | ||
sp := SourceProperty{ | ||
Source: "anything", | ||
Confidence: 80, | ||
} | ||
|
||
require.Equal(t, "anything", sp.Source) | ||
require.Equal(t, 80, sp.Confidence) | ||
require.Equal(t, sp.PropertyType(), model.SourceProperty) | ||
}) | ||
|
||
t.Run("Test successful JSON serialization of SourceProperty", func(t *testing.T) { | ||
sp := SourceProperty{ | ||
Source: "anything", | ||
Confidence: 80, | ||
} | ||
|
||
jsonData, err := sp.JSON() | ||
|
||
require.NoError(t, err) | ||
require.JSONEq(t, `{"name":"anything", "confidence":80}`, string(jsonData)) | ||
}) | ||
} |