resize_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2022 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. "github.com/lf-edge/ekuiper/internal/conf"
  17. kctx "github.com/lf-edge/ekuiper/internal/topo/context"
  18. "github.com/lf-edge/ekuiper/internal/topo/state"
  19. "github.com/lf-edge/ekuiper/pkg/api"
  20. "io/ioutil"
  21. "reflect"
  22. "testing"
  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. var 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 := ioutil.ReadFile(tt.image)
  40. if err != nil {
  41. t.Errorf("Failed to read image file %s", tt.image)
  42. continue
  43. }
  44. resized, err := ioutil.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. }