stream_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package api
  15. import (
  16. "testing"
  17. "time"
  18. "github.com/stretchr/testify/assert"
  19. "github.com/stretchr/testify/require"
  20. )
  21. func TestDefaultSourceTupleResult(t *testing.T) {
  22. now := time.Now()
  23. st := NewDefaultSourceTupleWithTime(nil, nil, now)
  24. assert.Equal(t, &DefaultSourceTuple{
  25. Mess: nil,
  26. M: nil,
  27. Time: now,
  28. }, st)
  29. assert.Nil(t, st.Message())
  30. assert.Nil(t, st.Meta())
  31. assert.Equal(t, now, st.Timestamp())
  32. st = NewDefaultSourceTuple(nil, nil)
  33. assert.Equal(t, &DefaultSourceTuple{
  34. Mess: nil,
  35. M: nil,
  36. Time: st.Time,
  37. }, st)
  38. assert.Nil(t, st.Message())
  39. assert.Nil(t, st.Meta())
  40. assert.NotEqual(t, now, st.Timestamp())
  41. }
  42. func TestIsLongRunningScheduleRule(t *testing.T) {
  43. r := &Rule{}
  44. require.False(t, r.IsLongRunningScheduleRule())
  45. r.Options = &RuleOption{
  46. CronDatetimeRange: []DatetimeRange{
  47. {
  48. Begin: "1",
  49. End: "2",
  50. },
  51. },
  52. }
  53. require.True(t, r.IsLongRunningScheduleRule())
  54. r.Options.Cron = "123"
  55. r.Options.Duration = "123"
  56. require.False(t, r.IsLongRunningScheduleRule())
  57. }