Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
test: add test for init-osm-controller methods
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Leigh <[email protected]>
  • Loading branch information
allenlsy committed Jun 8, 2021
1 parent 7dd0fb2 commit 9da9514
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/init-osm-controller/init-osm-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,45 @@ func TestCreateDefaultMeshConfig(t *testing.T) {
assert.Equal(meshConfig.Spec.Observability.EnableDebugServer, false)
assert.Equal(meshConfig.Spec.Certificate.ServiceCertValidityDuration, "24h")
}

func TestValidateCLIParams(t *testing.T) {
assert := tassert.New(t)

// save original global values
prevOsmNamespace := osmNamespace

tests := []struct {
caseName string
setup func()
verify func(error)
}{
{
caseName: "osm-namespace is empty",
setup: func() {
osmNamespace = ""
},
verify: func(err error) {
assert.NotNil(err)
assert.Contains(err.Error(), "--osm-namespace")
},
},
{
caseName: "osm-namespace is valid",
setup: func() {
osmNamespace = "valid-ns"
},
verify: func(err error) {
assert.Nil(err)
},
},
}

for _, tc := range tests {
tc.setup()
err := validateCLIParams()
tc.verify(err)
}

// restore original global values
osmNamespace = prevOsmNamespace
}

0 comments on commit 9da9514

Please sign in to comment.