-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add test for dashboard/objects/data.go NewDataLayer
- Loading branch information
Showing
4 changed files
with
101 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package objects | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/cli" | ||
) | ||
|
||
func TestNewDataLayer(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
namespaces []string | ||
version string | ||
helmConfig HelmConfigGetter | ||
errorExpected bool | ||
}{ | ||
{ | ||
name: "should return error when namespaces is nil", | ||
namespaces: nil, | ||
version: "1.0.0", | ||
helmConfig: nil, | ||
errorExpected: true, | ||
}, | ||
{ | ||
name: "should return error when namespaces is empty", | ||
namespaces: []string{}, | ||
version: "1.0.0", | ||
helmConfig: nil, | ||
errorExpected: true, | ||
}, | ||
{ | ||
name: "should return error when version is empty", | ||
namespaces: []string{"namespace1", "namespace2"}, | ||
version: "", | ||
helmConfig: nil, | ||
errorExpected: true, | ||
}, | ||
{ | ||
name: "should return error when helm config is nil", | ||
namespaces: []string{"namespace1", "namespace2"}, | ||
version: "1.0.0", | ||
helmConfig: nil, | ||
errorExpected: true, | ||
}, | ||
{ | ||
name: "should return data layer when all parameters are correct", | ||
namespaces: []string{ | ||
"namespace1", | ||
"namespace2", | ||
}, | ||
version: "1.0.0", | ||
helmConfig: func(sett *cli.EnvSettings, ns string) (*action.Configuration, error) { | ||
return &action.Configuration{}, nil | ||
}, | ||
errorExpected: false, | ||
}, | ||
} | ||
for _, tt := range testCases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
dl, err := NewDataLayer(tt.namespaces, tt.version, tt.helmConfig) | ||
if tt.errorExpected { | ||
assert.Error(t, err, "Expected error but got nil") | ||
} else { | ||
assert.Nil(t, err, "NewDataLayer returned an error: %v", err) | ||
assert.NotNil(t, dl, "NewDataLayer returned nil") | ||
assert.Equal(t, tt.namespaces, dl.Namespaces, "NewDataLayer returned incorrect namespaces: %v", dl.Namespaces) | ||
assert.NotNil(t, dl.Cache, "NewDataLayer returned nil cache") | ||
assert.Equal(t, tt.version, dl.StatusInfo.CurVer, "NewDataLayer returned incorrect version: %v", dl.StatusInfo.CurVer) | ||
assert.False(t, dl.StatusInfo.Analytics, "NewDataLayer returned incorrect version: %v", dl.StatusInfo.CurVer) | ||
assert.NotNil(t, dl.appPerContext, "NewDataLayer returned nil appPerContext") | ||
assert.NotNil(t, dl.ConfGen, "NewDataLayer returned nil ConfGen") | ||
|
||
} | ||
}) | ||
} | ||
} |