Skip to content

Commit

Permalink
add default configure to template
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzp1996 committed Oct 9, 2022
1 parent 3534391 commit 8a95b17
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sharedmain/sharedmain_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedmain_test
package sharedmain

import (
"testing"
Expand Down
41 changes: 32 additions & 9 deletions sharedmain/sharedmain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,46 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedmain_test
package sharedmain

import (
"github.com/katanomi/pkg/sharedmain"
"flag"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = BeforeSuite(func() {
ParseFlag()
})

var _ = Describe("Sharedmain", func() {
Context("ParseFlag should work as except", func() {
It("If flag is not provided,should return the default value", func() {
sharedmain.ParseFlag()
Expect(sharedmain.QPS).To(Equal(float64(sharedmain.DefaultQPS)))
Expect(sharedmain.Burst).To(Equal(sharedmain.DefaultBurst))
Expect(sharedmain.Timeout).To(Equal(sharedmain.DefaultTimeout))
Expect(sharedmain.ConfigFile).To(Equal(""))

When("flag not provided", func() {
It("return default values", func() {
Expect(QPS).To(Equal(float64(DefaultQPS)))
Expect(Burst).To(Equal(DefaultBurst))
Expect(Timeout).To(Equal(DefaultTimeout))
Expect(ConfigFile).To(Equal(""))
})
})

When("flag proviede", func() {
BeforeEach(func() {
flag.CommandLine.Parse([]string{
"--kube-api-timeout", "20s",
"--kube-api-qps", "80",
"--kube-api-burst", "90",
"--config", "config",
})
})
It("return configured values", func() {
Expect(QPS).To(Equal(float64(80)))
Expect(Burst).To(Equal(90))
Expect(Timeout).To(Equal(20 * time.Second))
Expect(ConfigFile).To(Equal("config"))
})
})

})

0 comments on commit 8a95b17

Please sign in to comment.