resize_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2022-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 main
  15. import (
  16. "os"
  17. "reflect"
  18. "testing"
  19. "github.com/lf-edge/ekuiper/internal/conf"
  20. kctx "github.com/lf-edge/ekuiper/internal/topo/context"
  21. "github.com/lf-edge/ekuiper/internal/topo/state"
  22. "github.com/lf-edge/ekuiper/pkg/api"
  23. )
  24. func TestResize(t *testing.T) {
  25. contextLogger := conf.Log.WithField("rule", "testExec")
  26. ctx := kctx.WithValue(kctx.Background(), kctx.LoggerKey, contextLogger)
  27. tempStore, _ := state.CreateStore("mockRule0", api.AtMostOnce)
  28. fctx := kctx.NewDefaultFuncContext(ctx.WithMeta("mockRule0", "test", tempStore), 2)
  29. tests := []struct {
  30. image string
  31. result string
  32. }{
  33. {
  34. image: "img.png",
  35. result: "resized.png",
  36. },
  37. }
  38. for i, tt := range tests {
  39. payload, err := os.ReadFile(tt.image)
  40. if err != nil {
  41. t.Errorf("Failed to read image file %s", tt.image)
  42. continue
  43. }
  44. resized, err := os.ReadFile(tt.result)
  45. if err != nil {
  46. t.Errorf("Failed to read result image file %s", tt.result)
  47. continue
  48. }
  49. result, _ := ResizeWithChan.Exec([]interface{}{
  50. payload, 100, 100,
  51. }, fctx)
  52. if !reflect.DeepEqual(result, resized) {
  53. t.Errorf("%d result mismatch", i)
  54. }
  55. }
  56. }