-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from AssetMantle/deepanshu
Deepanshu
- Loading branch information
Showing
9 changed files
with
108 additions
and
8 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 @@ | ||
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package define_enabled | ||
|
||
import ( | ||
baseData "github.com/AssetMantle/schema/go/data/base" | ||
errorConstants "github.com/AssetMantle/schema/go/errors/constants" | ||
baseParameters "github.com/AssetMantle/schema/go/parameters/base" | ||
"github.com/AssetMantle/schema/go/properties/base" | ||
constantProperties "github.com/AssetMantle/schema/go/properties/constants" | ||
|
||
baseHelpers "github.com/AssetMantle/modules/helpers/base" | ||
) | ||
|
||
var ID = constantProperties.DefineEnabledProperty.GetKey() | ||
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewBooleanData(false))) | ||
|
||
func validator(i interface{}) error { | ||
switch value := i.(type) { | ||
case string: | ||
_, err := baseData.PrototypeBooleanData().FromString(value) | ||
return err | ||
default: | ||
return errorConstants.IncorrectFormat.Wrapf("incorrect type for defineEnabled parameter, expected %s type as string, got %T", baseData.NewBooleanData(false).GetTypeID().AsString(), i) | ||
} | ||
} | ||
|
||
var ValidatableParameter = baseHelpers.NewValidatableParameter(Parameter, validator) |
41 changes: 41 additions & 0 deletions
41
x/classifications/parameters/define_enabled/parameter_test.go
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,41 @@ | ||
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package define_enabled | ||
|
||
import ( | ||
"testing" | ||
|
||
baseData "github.com/AssetMantle/schema/go/data/base" | ||
baseIDs "github.com/AssetMantle/schema/go/ids/base" | ||
baseParameters "github.com/AssetMantle/schema/go/parameters/base" | ||
baseProperties "github.com/AssetMantle/schema/go/properties/base" | ||
) | ||
|
||
func Test_validator(t *testing.T) { | ||
type args struct { | ||
i interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantError bool | ||
}{ | ||
{"-ve incorrectFormat", args{baseIDs.NewStringID("")}, true}, | ||
{"+ve", args{Parameter}, false}, | ||
{"-ve InvalidParameter", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID(""), baseData.NewStringData("")))}, true}, | ||
{"+ve with booleanData", args{baseData.NewBooleanData(false)}, false}, | ||
{"-ve with different type of Data", args{baseData.NewStringData("stringData")}, true}, | ||
{"+ve with true booleanData", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("defineEnabled"), baseData.NewBooleanData(true)))}, false}, | ||
{"+ve with false booleanData", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("defineEnabled"), baseData.NewBooleanData(false)))}, false}, | ||
{"+ve with incorrect ID", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID"), baseData.NewBooleanData(false)))}, true}, | ||
{"-ve nil", args{}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validator(tt.args.i); (err != nil) != tt.wantError { | ||
t.Errorf("validator() error = %v, wantErr %v", err, tt.wantError) | ||
} | ||
}) | ||
} | ||
} |
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